lok: impress: show only supported transitions in the side pane
[LibreOffice.git] / sfx2 / source / doc / oleprops.hxx
blobe5cb4cffa71b83b92b8342eaca571a629a038617
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SFX2_SOURCE_DOC_OLEPROPS_HXX
21 #define INCLUDED_SFX2_SOURCE_DOC_OLEPROPS_HXX
23 #include <map>
24 #include <memory>
25 #include <osl/thread.h>
26 #include <rtl/ustring.hxx>
27 #include <sot/storage.hxx>
28 #include <vcl/bitmapex.hxx>
30 #include <com/sun/star/util/DateTime.hpp>
31 #include <com/sun/star/util/Date.hpp>
34 //namespace {
37 // property type IDs
38 const sal_Int32 PROPTYPE_INT16 = 2;
39 const sal_Int32 PROPTYPE_INT32 = 3;
40 const sal_Int32 PROPTYPE_FLOAT = 4;
41 const sal_Int32 PROPTYPE_DOUBLE = 5;
42 const sal_Int32 PROPTYPE_DATE = 7;
43 const sal_Int32 PROPTYPE_STRING = 8;
44 const sal_Int32 PROPTYPE_STATUS = 10;
45 const sal_Int32 PROPTYPE_BOOL = 11;
46 const sal_Int32 PROPTYPE_VARIANT = 12;
47 const sal_Int32 PROPTYPE_INT8 = 16;
48 const sal_Int32 PROPTYPE_UINT8 = 17;
49 const sal_Int32 PROPTYPE_UINT16 = 18;
50 const sal_Int32 PROPTYPE_UINT32 = 19;
51 const sal_Int32 PROPTYPE_INT64 = 20;
52 const sal_Int32 PROPTYPE_UINT64 = 21;
53 const sal_Int32 PROPTYPE_STRING8 = 30;
54 const sal_Int32 PROPTYPE_STRING16 = 31;
55 const sal_Int32 PROPTYPE_FILETIME = 64;
56 const sal_Int32 PROPTYPE_BLOB = 65;
57 const sal_Int32 PROPTYPE_CLIPFMT = 71;
59 // static property IDs
60 const sal_Int32 PROPID_DICTIONARY = 0;
61 const sal_Int32 PROPID_CODEPAGE = 1;
62 const sal_Int32 PROPID_FIRSTCUSTOM = 2;
64 // property IDs for GlobalDocPropertySet
65 const sal_Int32 PROPID_TITLE = 2;
66 const sal_Int32 PROPID_SUBJECT = 3;
67 const sal_Int32 PROPID_AUTHOR = 4;
68 const sal_Int32 PROPID_KEYWORDS = 5;
69 const sal_Int32 PROPID_COMMENTS = 6;
70 const sal_Int32 PROPID_TEMPLATE = 7;
71 const sal_Int32 PROPID_LASTAUTHOR = 8;
72 const sal_Int32 PROPID_REVNUMBER = 9;
73 const sal_Int32 PROPID_EDITTIME = 10;
74 const sal_Int32 PROPID_LASTPRINTED = 11;
75 const sal_Int32 PROPID_CREATED = 12;
76 const sal_Int32 PROPID_LASTSAVED = 13;
77 const sal_Int32 PROPID_THUMBNAIL = 17;
79 // some Builtin properties
80 const sal_Int32 PROPID_CATEGORY = 0x2;
81 const sal_Int32 PROPID_COMPANY = 0xf;
82 const sal_Int32 PROPID_MANAGER = 0xe;
83 // predefined codepages
84 const sal_uInt16 CODEPAGE_UNKNOWN = 0;
85 const sal_uInt16 CODEPAGE_UNICODE = 1200;
86 const sal_uInt16 CODEPAGE_UTF8 = 65001;
88 // predefined clipboard format IDs
89 const sal_Int32 CLIPFMT_WIN = -1;
91 // predefined clipboard data format IDs
92 const sal_Int32 CLIPDATAFMT_DIB = 8;
95 /** Helper for classes that need text encoding settings.
97 Classes derived from this class will include functions to store and use
98 text encoding settings and to convert Windows codepage constants.
100 class SfxOleTextEncoding
102 public:
103 explicit SfxOleTextEncoding() :
104 mxTextEnc( new rtl_TextEncoding( osl_getThreadTextEncoding() ) ) {}
105 explicit SfxOleTextEncoding( rtl_TextEncoding eTextEnc ) :
106 mxTextEnc( new rtl_TextEncoding( eTextEnc ) ) {}
108 /** Returns the current text encoding identifier. */
109 rtl_TextEncoding GetTextEncoding() const { return *mxTextEnc; }
110 /** Sets the passed text encoding. */
111 void SetTextEncoding( rtl_TextEncoding eTextEnc ) { *mxTextEnc = eTextEnc; }
113 /** Returns true, if this object contains Unicode text encoding. */
114 bool IsUnicode() const { return GetTextEncoding() == RTL_TEXTENCODING_UCS2; }
115 /** Sets Unicode text encoding to this object. */
116 void SetUnicode() { SetTextEncoding( RTL_TEXTENCODING_UCS2 ); }
118 /** Converts the current settings to a Windows codepage identifier. */
119 sal_uInt16 GetCodePage() const;
120 /** Sets the current text encoding from a Windows codepage identifier. */
121 void SetCodePage( sal_uInt16 nCodePage );
123 private:
124 std::shared_ptr< rtl_TextEncoding > mxTextEnc;
128 /** Helper for classes that need to load or save string values.
130 Classes derived from this class contain functions to load and save string
131 values with the text encoding passed in the constructor.
133 class SfxOleStringHelper : public SfxOleTextEncoding
135 public:
136 /** Creates a string helper object depending on an external text encoding. */
137 explicit SfxOleStringHelper( const SfxOleTextEncoding& rTextEnc ) :
138 SfxOleTextEncoding( rTextEnc ) {}
139 /** Creates a string helper object with own text encoding. */
140 explicit SfxOleStringHelper( rtl_TextEncoding eTextEnc ) :
141 SfxOleTextEncoding( eTextEnc ) {}
143 /** Loads a string from the passed stream with current encoding (maybe Unicode). */
144 OUString LoadString8( SvStream& rStrm ) const;
145 /** Saves a string to the passed stream with current encoding (maybe Unicode). */
146 void SaveString8( SvStream& rStrm, const OUString& rValue ) const;
148 /** Loads a Unicode string from the passed stream, ignores own encoding. */
149 static OUString LoadString16( SvStream& rStrm );
150 /** Saves a Unicode string to the passed stream, ignores own encoding. */
151 static void SaveString16( SvStream& rStrm, const OUString& rValue );
153 private:
154 OUString ImplLoadString8( SvStream& rStrm ) const;
155 static OUString ImplLoadString16( SvStream& rStrm );
156 void ImplSaveString8( SvStream& rStrm, const OUString& rValue ) const;
157 static void ImplSaveString16( SvStream& rStrm, const OUString& rValue );
161 /** Base class for all classes related to OLE property sets.
163 Derived classes have to implement the pure virtual functions ImplLoad() and
164 ImplSave().
166 class SfxOleObjectBase
168 public:
169 explicit SfxOleObjectBase() : mnErrCode( ERRCODE_NONE ) {}
170 virtual ~SfxOleObjectBase();
172 /** Returns the current error code. */
173 ErrCode const & GetError() const { return mnErrCode; }
175 /** Loads this object from the passed stream. Calls virtual ImplLoad(). */
176 ErrCode const & Load( SvStream& rStrm );
177 /** Saves this object to the passed stream. Calls virtual ImplSave(). */
178 ErrCode const & Save( SvStream& rStrm );
180 protected:
181 /** Sets the passed error code. Will be returned by Load() and Save() functions.
182 Always the first error code is stored. Multiple calls have no effect. */
183 void SetError( ErrCode nErrCode ) { if( mnErrCode == ERRCODE_NONE ) mnErrCode = nErrCode; }
184 /** Loads the passed object from the stream. Sets returned error code as own error. */
185 void LoadObject( SvStream& rStrm, SfxOleObjectBase& rObj );
186 /** Saves the passed object to the stream. Sets returned error code as own error. */
187 void SaveObject( SvStream& rStrm, SfxOleObjectBase& rObj );
189 private:
190 /** Derived classes implement loading the object from the passed steam. */
191 virtual void ImplLoad( SvStream& rStrm ) = 0;
192 /** Derived classes implement saving the object to the passed steam. */
193 virtual void ImplSave( SvStream& rStrm ) = 0;
195 private:
196 ErrCode mnErrCode; /// Current error code.
200 /** Base class for all OLE property objects. */
201 class SfxOlePropertyBase : public SfxOleObjectBase
203 public:
204 explicit SfxOlePropertyBase( sal_Int32 nPropId, sal_Int32 nPropType ) :
205 mnPropId( nPropId ), mnPropType( nPropType ) {}
207 sal_Int32 GetPropId() const { return mnPropId; }
208 sal_Int32 GetPropType() const { return mnPropType; }
210 protected:
211 void SetPropType( sal_Int32 nPropType ) { mnPropType = nPropType; }
213 private:
214 sal_Int32 const mnPropId;
215 sal_Int32 mnPropType;
218 typedef std::shared_ptr< SfxOlePropertyBase > SfxOlePropertyRef;
221 /** Property representing the codepage used to encode bytestrings in the entire property set. */
222 class SfxOleCodePageProperty : public SfxOlePropertyBase, public SfxOleTextEncoding
224 public:
225 explicit SfxOleCodePageProperty();
227 private:
228 virtual void ImplLoad( SvStream& rStrm ) override;
229 virtual void ImplSave( SvStream& rStrm ) override;
233 /** Property containing custom names for other properties in the property set. */
234 class SfxOleDictionaryProperty : public SfxOlePropertyBase, public SfxOleStringHelper
236 public:
237 explicit SfxOleDictionaryProperty( const SfxOleTextEncoding& rTextEnc );
239 /** Returns true, if the property contains at least one custom property name. */
240 bool HasPropertyNames() const { return !maPropNameMap.empty(); }
241 /** Prepares the property for loading. Does not affect contained names for its own. */
242 void SetNameCount( sal_Int32 nNameCount ) { SetPropType( nNameCount ); }
244 /** Returns the custom name for the passed property ID, or an empty string, if name not found. */
245 OUString GetPropertyName( sal_Int32 nPropId ) const;
246 /** Sets a custom name for the passed property ID. */
247 void SetPropertyName( sal_Int32 nPropId, const OUString& rPropName );
249 private:
250 virtual void ImplLoad( SvStream& rStrm ) override;
251 virtual void ImplSave( SvStream& rStrm ) override;
253 private:
254 typedef ::std::map< sal_Int32, OUString > SfxOlePropNameMap;
255 SfxOlePropNameMap maPropNameMap;
259 /** A section in a property set. Contains properties with unique identifiers. */
260 class SfxOleSection : public SfxOleObjectBase
262 private:
263 typedef ::std::map< sal_Int32, SfxOlePropertyRef > SfxOlePropMap;
265 public:
266 explicit SfxOleSection( bool bSupportsDict );
268 /** Returns the property with the passed ID, or an empty reference, if nothing found. */
269 SfxOlePropertyRef GetProperty( sal_Int32 nPropId ) const;
270 /** Returns the value of a signed int32 property with the passed ID in rnValue.
271 @return true = Property found, rnValue is valid; false = Property not found. */
272 bool GetInt32Value( sal_Int32& rnValue, sal_Int32 nPropId ) const;
273 /** Returns the value of a floating-point property with the passed ID in rfValue.
274 @return true = Property found, rfValue is valid; false = Property not found. */
275 bool GetDoubleValue( double& rfValue, sal_Int32 nPropId ) const;
276 /** Returns the value of a boolean property with the passed ID in rbValue.
277 @return true = Property found, rbValue is valid; false = Property not found. */
278 bool GetBoolValue( bool& rbValue, sal_Int32 nPropId ) const;
279 /** Returns the value of a string property with the passed ID in rValue.
280 @return true = Property found, rValue is valid; false = Property not found. */
281 bool GetStringValue( OUString& rValue, sal_Int32 nPropId ) const;
282 /** Returns the value of a time stamp property with the passed ID in rValue.
283 @return true = Property found, rValue is valid; false = Property not found. */
284 bool GetFileTimeValue( css::util::DateTime& rValue, sal_Int32 nPropId ) const;
285 /** Returns the value of a date property with the passed ID in rValue.
286 @return true = Property found, rValue is valid; false = Property not found. */
287 bool GetDateValue( css::util::Date& rValue, sal_Int32 nPropId ) const;
289 /** Adds the passed property to the property set. Drops an existing old property. */
290 void SetProperty( const SfxOlePropertyRef& xProp );
291 /** Inserts a signed int32 property with the passed value. */
292 void SetInt32Value( sal_Int32 nPropId, sal_Int32 nValue );
293 /** Inserts a floating-point property with the passed value. */
294 void SetDoubleValue( sal_Int32 nPropId, double fValue );
295 /** Inserts a boolean property with the passed value. */
296 void SetBoolValue( sal_Int32 nPropId, bool bValue );
297 /** Inserts a string property with the passed value.
298 @return true = Property inserted; false = String was empty, property not inserted. */
299 bool SetStringValue( sal_Int32 nPropId, const OUString& rValue );
300 /** Inserts a time stamp property with the passed value. */
301 void SetFileTimeValue( sal_Int32 nPropId, const css::util::DateTime& rValue );
302 /** Inserts a date property with the passed value. */
303 void SetDateValue( sal_Int32 nPropId, const css::util::Date& rValue );
304 /** Inserts a thumbnail property from the passed meta file. */
305 void SetThumbnailValue( sal_Int32 nPropId,
306 const css::uno::Sequence<sal_Int8> & i_rData);
307 /** Inserts a BLOB property with the passed data. */
308 void SetBlobValue( sal_Int32 nPropId,
309 const css::uno::Sequence<sal_Int8> & i_rData);
311 /** Returns the value of the property with the passed ID in a UNO any. */
312 css::uno::Any GetAnyValue( sal_Int32 nPropId ) const;
313 /** Inserts a property created from the passed any.
314 @return true = Property converted and inserted; false = Property type not supported. */
315 bool SetAnyValue( sal_Int32 nPropId, const css::uno::Any& rValue );
317 /** Returns the custom name for the passed property ID, or an empty string, if name not found. */
318 OUString GetPropertyName( sal_Int32 nPropId ) const;
319 /** Sets a custom name for the passed property ID. */
320 void SetPropertyName( sal_Int32 nPropId, const OUString& rPropName );
322 /** Returns the identifiers of all existing properties in the passed vector. */
323 void GetPropertyIds( ::std::vector< sal_Int32 >& rPropIds ) const;
324 /** Returns a property identifier not used in this section. */
325 sal_Int32 GetFreePropertyId() const;
327 private:
328 virtual void ImplLoad( SvStream& rStrm ) override;
329 virtual void ImplSave( SvStream& rStrm ) override;
331 bool SeekToPropertyPos( SvStream& rStrm, sal_uInt32 nPropPos ) const;
332 void LoadProperty( SvStream& rStrm, sal_Int32 nPropId );
333 void SaveProperty( SvStream& rStrm, SfxOlePropertyBase& rProp, sal_uInt64 & rnPropPosPos );
335 private:
336 SfxOlePropMap maPropMap; /// All properties in this section, by identifier.
337 SfxOleCodePageProperty maCodePageProp; /// The codepage property.
338 SfxOleDictionaryProperty maDictProp; /// The dictionary property.
339 sal_uInt64 mnStartPos; /// Start stream position of the section.
340 bool const mbSupportsDict; /// true = section supports dictionary.
343 typedef std::shared_ptr< SfxOleSection > SfxOleSectionRef;
346 /** Enumerates different section types in OLE property sets. */
347 enum SfxOleSectionType
349 SECTION_GLOBAL, /// Globally defined properties.
350 SECTION_BUILTIN, /// Properties built into MS Office.
351 SECTION_CUSTOM /// Custom properties.
355 /** Represents a complete property set, may consist of several property sections. */
356 class SfxOlePropertySet : public SfxOleObjectBase
358 public:
359 explicit SfxOlePropertySet() {}
361 /** Loads this object from the passed storage. */
362 ErrCode const & LoadPropertySet( SotStorage* pStrg, const OUString& rStrmName );
363 /** Saves this object to the passed storage. */
364 ErrCode const & SavePropertySet( SotStorage* pStrg, const OUString& rStrmName );
366 /** Returns the specified section, or an empty reference, if nothing found. */
367 SfxOleSectionRef GetSection( SfxOleSectionType eSection ) const;
368 /** Returns the specified section, or an empty reference, if nothing found. */
369 SfxOleSectionRef GetSection( const SvGlobalName& rSectionGuid ) const;
371 /** Creates and returns the specified section, or just returns it if it already exists. */
372 SfxOleSection& AddSection( SfxOleSectionType eSection );
373 /** Creates and returns the specified section, or just returns it if it already exists. */
374 SfxOleSection& AddSection( const SvGlobalName& rSectionGuid );
376 private:
377 virtual void ImplLoad( SvStream& rStrm ) override;
378 virtual void ImplSave( SvStream& rStrm ) override;
380 /** Returns the GUID for the specified section. */
381 static const SvGlobalName& GetSectionGuid( SfxOleSectionType eSection );
383 private:
384 typedef ::std::map< SvGlobalName, SfxOleSectionRef > SfxOleSectionMap;
385 SfxOleSectionMap maSectionMap;
388 #endif
390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */