Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include "oleprops.hxx"
22 : :
23 : : #include <comphelper/types.hxx>
24 : : #include <tools/debug.hxx>
25 : : #include <tools/datetime.hxx>
26 : : #include <rtl/tencinfo.h>
27 : : #include <rtl/strbuf.hxx>
28 : :
29 : : // ============================================================================
30 : :
31 : :
32 : : // ============================================================================
33 : :
34 : : #define STREAM_BUFFER_SIZE 2048
35 : :
36 : : // usings
37 : : using ::rtl::OUString;
38 : : using ::com::sun::star::uno::Any;
39 : : using ::com::sun::star::uno::makeAny;
40 : :
41 : : using namespace ::com::sun::star;
42 : :
43 : : #define TIMESTAMP_INVALID_DATETIME ( DateTime ( Date ( 1, 1, 1601 ), Time ( 0, 0, 0 ) ) ) /// Invalid value for date and time to create invalid instance of TimeStamp.
44 : : #define TIMESTAMP_INVALID_UTILDATETIME ( util::DateTime ( 0, 0, 0, 0, 1, 1, 1601 ) ) /// Invalid value for date and time to create invalid instance of TimeStamp.
45 : : #define TIMESTAMP_INVALID_UTILDATE ( util::Date ( 1, 1, 1601 ) ) /// Invalid value for date to create invalid instance of TimeStamp.
46 : :
47 : : static
48 : 458 : bool operator==(const util::DateTime &i_rLeft, const util::DateTime &i_rRight)
49 : : {
50 : : return i_rLeft.Year == i_rRight.Year
51 : : && i_rLeft.Month == i_rRight.Month
52 : : && i_rLeft.Day == i_rRight.Day
53 : : && i_rLeft.Hours == i_rRight.Hours
54 : : && i_rLeft.Minutes == i_rRight.Minutes
55 : : && i_rLeft.Seconds == i_rRight.Seconds
56 [ + + ][ + + ]: 458 : && i_rLeft.HundredthSeconds == i_rRight.HundredthSeconds;
[ + + ][ + + ]
[ + + ][ + - ]
[ + - ]
57 : : }
58 : :
59 : : static
60 : 0 : bool operator==(const util::Date &i_rLeft, const util::Date &i_rRight)
61 : : {
62 : : return i_rLeft.Year == i_rRight.Year
63 : : && i_rLeft.Month == i_rRight.Month
64 [ # # ][ # # ]: 0 : && i_rLeft.Day == i_rRight.Day;
[ # # ]
65 : : }
66 : :
67 : : // ============================================================================
68 : :
69 : : /** Property representing a signed 32-bit integer value. */
70 [ - + ]: 1414 : class SfxOleInt32Property : public SfxOlePropertyBase
71 : : {
72 : : public:
73 : : explicit SfxOleInt32Property( sal_Int32 nPropId, sal_Int32 nValue = 0 );
74 : :
75 : 0 : inline sal_Int32 GetValue() const { return mnValue; }
76 : : inline void SetValue( sal_Int32 nValue ) { mnValue = nValue; }
77 : :
78 : : private:
79 : : virtual void ImplLoad( SvStream& rStrm );
80 : : virtual void ImplSave( SvStream& rStrm );
81 : :
82 : : private:
83 : : sal_Int32 mnValue;
84 : : };
85 : :
86 : : // ============================================================================
87 : :
88 : : /** Property representing a floating-point value. */
89 [ # # ]: 0 : class SfxOleDoubleProperty : public SfxOlePropertyBase
90 : : {
91 : : public:
92 : : explicit SfxOleDoubleProperty( sal_Int32 nPropId, double fValue = 0.0 );
93 : :
94 : 0 : inline double GetValue() const { return mfValue; }
95 : : inline void SetValue( double fValue ) { mfValue = fValue; }
96 : :
97 : : private:
98 : : virtual void ImplLoad( SvStream& rStrm );
99 : : virtual void ImplSave( SvStream& rStrm );
100 : :
101 : : private:
102 : : double mfValue;
103 : : };
104 : :
105 : : // ============================================================================
106 : :
107 : : /** Property representing a boolean value. */
108 [ - + ]: 872 : class SfxOleBoolProperty : public SfxOlePropertyBase
109 : : {
110 : : public:
111 : : explicit SfxOleBoolProperty( sal_Int32 nPropId, bool bValue = false );
112 : :
113 : 0 : inline bool GetValue() const { return mbValue; }
114 : : inline void SetValue( bool bValue ) { mbValue = bValue; }
115 : :
116 : : private:
117 : : virtual void ImplLoad( SvStream& rStrm );
118 : : virtual void ImplSave( SvStream& rStrm );
119 : :
120 : : private:
121 : : bool mbValue;
122 : : };
123 : :
124 : : // ============================================================================
125 : :
126 : : /** Base class for properties that contain a single string value. */
127 [ + - ][ + - ]: 941 : class SfxOleStringPropertyBase : public SfxOlePropertyBase, public SfxOleStringHelper
[ - + ]
128 : : {
129 : : public:
130 : : explicit SfxOleStringPropertyBase(
131 : : sal_Int32 nPropId, sal_Int32 nPropType,
132 : : const SfxOleTextEncoding& rTextEnc );
133 : : explicit SfxOleStringPropertyBase(
134 : : sal_Int32 nPropId, sal_Int32 nPropType,
135 : : const SfxOleTextEncoding& rTextEnc, const String& rValue );
136 : : explicit SfxOleStringPropertyBase(
137 : : sal_Int32 nPropId, sal_Int32 nPropType,
138 : : rtl_TextEncoding eTextEnc );
139 : :
140 : 734 : inline const String& GetValue() const { return maValue; }
141 : 917 : inline void SetValue( const String& rValue ) { maValue = rValue; }
142 : :
143 : : private:
144 : : String maValue;
145 : : };
146 : :
147 : : // ============================================================================
148 : :
149 : : /** Property representing a bytestring value. */
150 [ - + ]: 1882 : class SfxOleString8Property : public SfxOleStringPropertyBase
151 : : {
152 : : public:
153 : : explicit SfxOleString8Property(
154 : : sal_Int32 nPropId, const SfxOleTextEncoding& rTextEnc );
155 : : explicit SfxOleString8Property(
156 : : sal_Int32 nPropId, const SfxOleTextEncoding& rTextEnc,
157 : : const String& rValue );
158 : :
159 : : private:
160 : : virtual void ImplLoad( SvStream& rStrm );
161 : : virtual void ImplSave( SvStream& rStrm );
162 : : };
163 : :
164 : : // ============================================================================
165 : :
166 : : /** Property representing a Unicode string value. */
167 [ # # ]: 0 : class SfxOleString16Property : public SfxOleStringPropertyBase
168 : : {
169 : : public:
170 : : explicit SfxOleString16Property( sal_Int32 nPropId );
171 : :
172 : : private:
173 : : virtual void ImplLoad( SvStream& rStrm );
174 : : virtual void ImplSave( SvStream& rStrm );
175 : : };
176 : :
177 : : // ============================================================================
178 : :
179 : : /** Property representing a filetime value as defined by the Windows API. */
180 [ - + ]: 988 : class SfxOleFileTimeProperty : public SfxOlePropertyBase
181 : : {
182 : : public:
183 : : explicit SfxOleFileTimeProperty( sal_Int32 nPropId );
184 : : /** @param rDateTime Date and time as LOCAL time. */
185 : : explicit SfxOleFileTimeProperty( sal_Int32 nPropId, const util::DateTime& rDateTime );
186 : :
187 : : /** Returns the time value as LOCAL time. */
188 : 838 : inline const util::DateTime& GetValue() const { return maDateTime; }
189 : : /** @param rDateTime Date and time as LOCAL time. */
190 : : inline void SetValue( const util::DateTime& rDateTime ) { maDateTime = rDateTime; }
191 : :
192 : : private:
193 : : virtual void ImplLoad( SvStream& rStrm );
194 : : virtual void ImplSave( SvStream& rStrm );
195 : :
196 : : private:
197 : : util::DateTime maDateTime;
198 : : };
199 : :
200 : : /** Property representing a filetime value as defined by the Windows API. */
201 [ # # ]: 0 : class SfxOleDateProperty : public SfxOlePropertyBase
202 : : {
203 : : public:
204 : : explicit SfxOleDateProperty( sal_Int32 nPropId );
205 : :
206 : : /** Returns the date value as LOCAL time. */
207 : 0 : inline const util::Date& GetValue() const { return maDate; }
208 : : /** @param rDate Date as LOCAL time. */
209 : : inline void SetValue( const util::Date& rDate ) { maDate = rDate; }
210 : :
211 : : private:
212 : : virtual void ImplLoad( SvStream& rStrm );
213 : : virtual void ImplSave( SvStream& rStrm );
214 : :
215 : : private:
216 : : util::Date maDate;
217 : : };
218 : :
219 : : // ============================================================================
220 : :
221 : : /** Property representing a thumbnail picture.
222 : :
223 : : Currently, only saving this property is implemented.
224 : : */
225 [ # # ][ # # ]: 0 : class SfxOleThumbnailProperty : public SfxOlePropertyBase
226 : : {
227 : : public:
228 : : explicit SfxOleThumbnailProperty( sal_Int32 nPropId,
229 : : const uno::Sequence<sal_uInt8> & i_rData);
230 : :
231 : 0 : inline bool IsValid() const { return mData.getLength() > 0; }
232 : :
233 : : private:
234 : : virtual void ImplLoad( SvStream& rStrm );
235 : : virtual void ImplSave( SvStream& rStrm );
236 : :
237 : : private:
238 : : uno::Sequence<sal_uInt8> mData;
239 : : };
240 : :
241 : : // ============================================================================
242 : :
243 : : /** Property representing a BLOB (which presumably stands for binary large
244 : : object).
245 : :
246 : : Currently, only saving this property is implemented.
247 : : */
248 [ # # ][ # # ]: 0 : class SfxOleBlobProperty : public SfxOlePropertyBase
249 : : {
250 : : public:
251 : : explicit SfxOleBlobProperty( sal_Int32 nPropId,
252 : : const uno::Sequence<sal_uInt8> & i_rData);
253 : 0 : inline bool IsValid() const { return mData.getLength() > 0; }
254 : :
255 : : private:
256 : : virtual void ImplLoad( SvStream& rStrm );
257 : : virtual void ImplSave( SvStream& rStrm );
258 : :
259 : : private:
260 : : uno::Sequence<sal_uInt8> mData;
261 : : };
262 : :
263 : : // ============================================================================
264 : :
265 : 27 : sal_uInt16 SfxOleTextEncoding::GetCodePage() const
266 : : {
267 : 27 : sal_uInt16 nCodePage = IsUnicode() ? CODEPAGE_UNICODE :
268 [ - + ]: 27 : static_cast< sal_uInt16 >( rtl_getWindowsCodePageFromTextEncoding( *mxTextEnc ) );
269 [ + - ]: 27 : return (nCodePage == CODEPAGE_UNKNOWN) ? CODEPAGE_UTF8 : nCodePage;
270 : : }
271 : :
272 : 359 : void SfxOleTextEncoding::SetCodePage( sal_uInt16 nCodePage )
273 : : {
274 [ + + ]: 359 : if( nCodePage == CODEPAGE_UNICODE )
275 : 6 : SetUnicode();
276 : : else
277 : : {
278 : 353 : rtl_TextEncoding eTextEnc = rtl_getTextEncodingFromWindowsCodePage( nCodePage );
279 [ + - ]: 353 : if( eTextEnc != RTL_TEXTENCODING_DONTKNOW )
280 : 353 : *mxTextEnc = eTextEnc;
281 : : }
282 : 359 : }
283 : :
284 : : // ----------------------------------------------------------------------------
285 : :
286 : 950 : String SfxOleStringHelper::LoadString8( SvStream& rStrm ) const
287 : : {
288 [ - + ]: 950 : return IsUnicode() ? ImplLoadString16( rStrm ) : ImplLoadString8( rStrm );
289 : : }
290 : :
291 : 24 : void SfxOleStringHelper::SaveString8( SvStream& rStrm, const String& rValue ) const
292 : : {
293 [ - + ]: 24 : if( IsUnicode() )
294 : 0 : ImplSaveString16( rStrm, rValue );
295 : : else
296 : 24 : ImplSaveString8( rStrm, rValue );
297 : 24 : }
298 : :
299 : 0 : String SfxOleStringHelper::LoadString16( SvStream& rStrm ) const
300 : : {
301 : 0 : return ImplLoadString16( rStrm );
302 : : }
303 : :
304 : 0 : void SfxOleStringHelper::SaveString16( SvStream& rStrm, const String& rValue ) const
305 : : {
306 : 0 : ImplSaveString16( rStrm, rValue );
307 : 0 : }
308 : :
309 : 950 : String SfxOleStringHelper::ImplLoadString8( SvStream& rStrm ) const
310 : : {
311 [ + - ]: 950 : String aValue;
312 : : // read size field (signed 32-bit)
313 : 950 : sal_Int32 nSize(0);
314 [ + - ]: 950 : rStrm >> nSize;
315 : : // size field includes trailing NUL character
316 : : DBG_ASSERT( (0 < nSize) && (nSize <= 0xFFFF),
317 : : rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM(
318 : : "SfxOleStringHelper::ImplLoadString8 - invalid string of len ")).
319 : : append(nSize).getStr() );
320 [ + - ][ + - ]: 950 : if( (0 < nSize) && (nSize <= 0xFFFF) )
321 : : {
322 : : // load character buffer
323 [ + - ]: 950 : ::std::vector< sal_Char > aBuffer( static_cast< size_t >( nSize + 1 ), 0 );
324 [ + - ][ + - ]: 950 : rStrm.Read( &aBuffer.front(), static_cast< sal_Size >( nSize ) );
325 : : // create string from encoded character array
326 [ + - ][ + - ]: 950 : aValue = String( &aBuffer.front(), GetTextEncoding() );
[ + - ][ + - ]
[ + - ]
327 : : }
328 : 950 : return aValue;
329 : : }
330 : :
331 : 0 : String SfxOleStringHelper::ImplLoadString16( SvStream& rStrm ) const
332 : : {
333 [ # # ]: 0 : String aValue;
334 : : // read size field (signed 32-bit), may be buffer size or character count
335 : 0 : sal_Int32 nSize(0);
336 [ # # ]: 0 : rStrm >> nSize;
337 : : DBG_ASSERT( (0 < nSize) && (nSize <= 0xFFFF), "SfxOleStringHelper::ImplLoadString16 - invalid string" );
338 : : // size field includes trailing NUL character
339 [ # # ][ # # ]: 0 : if( (0 < nSize) && (nSize <= 0xFFFF) )
340 : : {
341 : : // load character buffer
342 [ # # ]: 0 : ::std::vector< sal_Unicode > aBuffer;
343 [ # # ]: 0 : aBuffer.reserve( static_cast< size_t >( nSize + 1 ) );
344 : : sal_uInt16 cChar;
345 [ # # ]: 0 : for( sal_Int32 nIdx = 0; nIdx < nSize; ++nIdx )
346 : : {
347 [ # # ]: 0 : rStrm >> cChar;
348 [ # # ]: 0 : aBuffer.push_back( static_cast< sal_Unicode >( cChar ) );
349 : : }
350 : : // stream is always padded to 32-bit boundary, skip 2 bytes on odd character count
351 [ # # ]: 0 : if( (nSize & 1) == 1 )
352 [ # # ]: 0 : rStrm.SeekRel( 2 );
353 : : // create string from character array
354 [ # # ]: 0 : aBuffer.push_back( 0 );
355 [ # # ][ # # ]: 0 : aValue = rtl::OUString( &aBuffer.front() );
356 : : }
357 : 0 : return aValue;
358 : : }
359 : :
360 : 24 : void SfxOleStringHelper::ImplSaveString8( SvStream& rStrm, const String& rValue ) const
361 : : {
362 : : // encode to byte string
363 [ + - ][ + - ]: 24 : rtl::OString aEncoded(rtl::OUStringToOString(rValue, GetTextEncoding()));
[ + - ]
364 : : // write size field (including trailing NUL character)
365 : 24 : sal_Int32 nSize = aEncoded.getLength() + 1;
366 [ + - ]: 24 : rStrm << nSize;
367 : : // write character array with trailing NUL character
368 [ + - ]: 24 : rStrm.Write(aEncoded.getStr(), aEncoded.getLength());
369 [ + - ]: 24 : rStrm << sal_uInt8( 0 );
370 : 24 : }
371 : :
372 : 0 : void SfxOleStringHelper::ImplSaveString16( SvStream& rStrm, const String& rValue ) const
373 : : {
374 : : // write size field (including trailing NUL character)
375 : 0 : sal_Int32 nSize = static_cast< sal_Int32 >( rValue.Len() + 1 );
376 : 0 : rStrm << nSize;
377 : : // write character array with trailing NUL character
378 [ # # ]: 0 : for( xub_StrLen nIdx = 0; nIdx < rValue.Len(); ++nIdx )
379 : 0 : rStrm << static_cast< sal_uInt16 >( rValue.GetChar( nIdx ) );
380 : 0 : rStrm << sal_uInt16( 0 );
381 : : // stream is always padded to 32-bit boundary, add 2 bytes on odd character count
382 [ # # ]: 0 : if( (nSize & 1) == 1 )
383 : 0 : rStrm << sal_uInt16( 0 );
384 : 0 : }
385 : :
386 : : // ----------------------------------------------------------------------------
387 : :
388 : 4146 : SfxOleObjectBase::~SfxOleObjectBase()
389 : : {
390 [ - + ]: 4146 : }
391 : :
392 : 3598 : ErrCode SfxOleObjectBase::Load( SvStream& rStrm )
393 : : {
394 : 3598 : mnErrCode = ERRCODE_NONE;
395 : 3598 : ImplLoad( rStrm );
396 : 3598 : SetError( rStrm.GetErrorCode() );
397 : 3598 : return GetError();
398 : : }
399 : :
400 : 132 : ErrCode SfxOleObjectBase::Save( SvStream& rStrm )
401 : : {
402 : 132 : mnErrCode = ERRCODE_NONE;
403 : 132 : ImplSave( rStrm );
404 : 132 : SetError( rStrm.GetErrorCode() );
405 : 132 : return GetError();
406 : : }
407 : :
408 : 775 : void SfxOleObjectBase::LoadObject( SvStream& rStrm, SfxOleObjectBase& rObj )
409 : : {
410 : 775 : SetError( rObj.Load( rStrm ) );
411 : 775 : }
412 : :
413 : 114 : void SfxOleObjectBase::SaveObject( SvStream& rStrm, SfxOleObjectBase& rObj )
414 : : {
415 : 114 : SetError( rObj.Save( rStrm ) );
416 : 114 : }
417 : :
418 : : // ----------------------------------------------------------------------------
419 : :
420 : 404 : SfxOleCodePageProperty::SfxOleCodePageProperty() :
421 [ + - ]: 404 : SfxOlePropertyBase( PROPID_CODEPAGE, PROPTYPE_INT16 )
422 : : {
423 : 404 : }
424 : :
425 : 359 : void SfxOleCodePageProperty::ImplLoad( SvStream& rStrm )
426 : : {
427 : : // property type is signed int16, but we use always unsigned int16 for codepages
428 : : sal_uInt16 nCodePage;
429 [ + - ]: 359 : rStrm >> nCodePage;
430 [ + - ]: 359 : SetCodePage( nCodePage );
431 : 359 : }
432 : :
433 : 27 : void SfxOleCodePageProperty::ImplSave( SvStream& rStrm )
434 : : {
435 : : // property type is signed int16, but we use always unsigned int16 for codepages
436 : 27 : rStrm << GetCodePage();
437 : 27 : }
438 : :
439 : : // ----------------------------------------------------------------------------
440 : :
441 : 707 : SfxOleInt32Property::SfxOleInt32Property( sal_Int32 nPropId, sal_Int32 nValue ) :
442 : : SfxOlePropertyBase( nPropId, PROPTYPE_INT32 ),
443 : 707 : mnValue( nValue )
444 : : {
445 : 707 : }
446 : :
447 : 707 : void SfxOleInt32Property::ImplLoad( SvStream& rStrm )
448 : : {
449 : 707 : rStrm >> mnValue;
450 : 707 : }
451 : :
452 : 0 : void SfxOleInt32Property::ImplSave( SvStream& rStrm )
453 : : {
454 : 0 : rStrm << mnValue;
455 : 0 : }
456 : :
457 : : // ----------------------------------------------------------------------------
458 : :
459 : 0 : SfxOleDoubleProperty::SfxOleDoubleProperty( sal_Int32 nPropId, double fValue ) :
460 : : SfxOlePropertyBase( nPropId, PROPTYPE_DOUBLE ),
461 : 0 : mfValue( fValue )
462 : : {
463 : 0 : }
464 : :
465 : 0 : void SfxOleDoubleProperty::ImplLoad( SvStream& rStrm )
466 : : {
467 : 0 : rStrm >> mfValue;
468 : 0 : }
469 : :
470 : 0 : void SfxOleDoubleProperty::ImplSave( SvStream& rStrm )
471 : : {
472 : 0 : rStrm << mfValue;
473 : 0 : }
474 : :
475 : : // ----------------------------------------------------------------------------
476 : :
477 : 436 : SfxOleBoolProperty::SfxOleBoolProperty( sal_Int32 nPropId, bool bValue ) :
478 : : SfxOlePropertyBase( nPropId, PROPTYPE_BOOL ),
479 : 436 : mbValue( bValue )
480 : : {
481 : 436 : }
482 : :
483 : 436 : void SfxOleBoolProperty::ImplLoad( SvStream& rStrm )
484 : : {
485 : 436 : sal_Int16 nValue(0);
486 [ + - ]: 436 : rStrm >> nValue;
487 : 436 : mbValue = nValue != 0;
488 : 436 : }
489 : :
490 : 0 : void SfxOleBoolProperty::ImplSave( SvStream& rStrm )
491 : : {
492 [ # # ]: 0 : rStrm << static_cast< sal_Int16 >( mbValue ? -1 : 0 );
493 : 0 : }
494 : :
495 : : // ----------------------------------------------------------------------------
496 : :
497 : 917 : SfxOleStringPropertyBase::SfxOleStringPropertyBase(
498 : : sal_Int32 nPropId, sal_Int32 nPropType, const SfxOleTextEncoding& rTextEnc ) :
499 : : SfxOlePropertyBase( nPropId, nPropType ),
500 [ + - ][ + - ]: 917 : SfxOleStringHelper( rTextEnc )
501 : : {
502 : 917 : }
503 : :
504 : 24 : SfxOleStringPropertyBase::SfxOleStringPropertyBase(
505 : : sal_Int32 nPropId, sal_Int32 nPropType, const SfxOleTextEncoding& rTextEnc, const String& rValue ) :
506 : : SfxOlePropertyBase( nPropId, nPropType ),
507 : : SfxOleStringHelper( rTextEnc ),
508 [ + - ][ + - ]: 24 : maValue( rValue )
509 : : {
510 : 24 : }
511 : :
512 : 0 : SfxOleStringPropertyBase::SfxOleStringPropertyBase(
513 : : sal_Int32 nPropId, sal_Int32 nPropType, rtl_TextEncoding eTextEnc ) :
514 : : SfxOlePropertyBase( nPropId, nPropType ),
515 [ # # ][ # # ]: 0 : SfxOleStringHelper( eTextEnc )
516 : : {
517 : 0 : }
518 : :
519 : : // ----------------------------------------------------------------------------
520 : :
521 : 917 : SfxOleString8Property::SfxOleString8Property(
522 : : sal_Int32 nPropId, const SfxOleTextEncoding& rTextEnc ) :
523 : 917 : SfxOleStringPropertyBase( nPropId, PROPTYPE_STRING8, rTextEnc )
524 : : {
525 : 917 : }
526 : :
527 : 24 : SfxOleString8Property::SfxOleString8Property(
528 : : sal_Int32 nPropId, const SfxOleTextEncoding& rTextEnc, const String& rValue ) :
529 : 24 : SfxOleStringPropertyBase( nPropId, PROPTYPE_STRING8, rTextEnc, rValue )
530 : : {
531 : 24 : }
532 : :
533 : 917 : void SfxOleString8Property::ImplLoad( SvStream& rStrm )
534 : : {
535 [ + - ]: 917 : SetValue( LoadString8( rStrm ) );
536 : 917 : }
537 : :
538 : 24 : void SfxOleString8Property::ImplSave( SvStream& rStrm )
539 : : {
540 : 24 : SaveString8( rStrm, GetValue() );
541 : 24 : }
542 : :
543 : : // ----------------------------------------------------------------------------
544 : :
545 : 0 : SfxOleString16Property::SfxOleString16Property( sal_Int32 nPropId ) :
546 : 0 : SfxOleStringPropertyBase( nPropId, PROPTYPE_STRING16, RTL_TEXTENCODING_UCS2 )
547 : : {
548 : 0 : }
549 : :
550 : 0 : void SfxOleString16Property::ImplLoad( SvStream& rStrm )
551 : : {
552 [ # # ]: 0 : SetValue( LoadString16( rStrm ) );
553 : 0 : }
554 : :
555 : 0 : void SfxOleString16Property::ImplSave( SvStream& rStrm )
556 : : {
557 : 0 : SaveString16( rStrm, GetValue() );
558 : 0 : }
559 : :
560 : : // ----------------------------------------------------------------------------
561 : :
562 : 458 : SfxOleFileTimeProperty::SfxOleFileTimeProperty( sal_Int32 nPropId ) :
563 : 458 : SfxOlePropertyBase( nPropId, PROPTYPE_FILETIME )
564 : : {
565 : 458 : }
566 : :
567 : 36 : SfxOleFileTimeProperty::SfxOleFileTimeProperty( sal_Int32 nPropId, const util::DateTime& rDateTime ) :
568 : : SfxOlePropertyBase( nPropId, PROPTYPE_FILETIME ),
569 : 36 : maDateTime( rDateTime )
570 : : {
571 : 36 : }
572 : :
573 : 458 : void SfxOleFileTimeProperty::ImplLoad( SvStream& rStrm )
574 : : {
575 : 458 : sal_uInt32 nLower(0), nUpper(0);
576 [ + - ][ + - ]: 458 : rStrm >> nLower >> nUpper;
577 [ + - ]: 458 : ::DateTime aDateTime = DateTime::CreateFromWin32FileDateTime( nLower, nUpper );
578 : : // note: editing duration is stored as offset to TIMESTAMP_INVALID_DATETIME
579 : : // of course we should not convert the time zone of a duration!
580 : : // heuristic to detect editing durations (which we assume to be < 1 year):
581 : : // check only the year, not the entire date
582 [ + - ][ + - ]: 458 : if ( aDateTime.GetYear() != TIMESTAMP_INVALID_DATETIME.GetYear() )
[ + + ]
583 [ + - ]: 302 : aDateTime.ConvertToLocalTime();
584 : 458 : maDateTime.Year = aDateTime.GetYear();
585 : 458 : maDateTime.Month = aDateTime.GetMonth();
586 : 458 : maDateTime.Day = aDateTime.GetDay();
587 : 458 : maDateTime.Hours = aDateTime.GetHour();
588 : 458 : maDateTime.Minutes = aDateTime.GetMin();
589 : 458 : maDateTime.Seconds = aDateTime.GetSec();
590 : 458 : maDateTime.HundredthSeconds = aDateTime.Get100Sec();
591 : 458 : }
592 : :
593 : 36 : void SfxOleFileTimeProperty::ImplSave( SvStream& rStrm )
594 : : {
595 : : DateTime aDateTimeUtc(
596 : : Date(
597 : : static_cast< sal_uInt16 >( maDateTime.Day ),
598 : : static_cast< sal_uInt16 >( maDateTime.Month ),
599 : : static_cast< sal_uInt16 >( maDateTime.Year ) ),
600 : : Time(
601 : : static_cast< sal_uIntPtr >( maDateTime.Hours ),
602 : : static_cast< sal_uIntPtr >( maDateTime.Minutes ),
603 : : static_cast< sal_uIntPtr >( maDateTime.Seconds ),
604 [ + - ][ + - ]: 36 : static_cast< sal_uIntPtr >( maDateTime.HundredthSeconds ) ) );
605 : : // invalid time stamp is not converted to UTC
606 : : // heuristic to detect editing durations (which we assume to be < 1 year):
607 : : // check only the year, not the entire date
608 [ + - ]: 108 : if( aDateTimeUtc.IsValidAndGregorian()
[ + - + + ]
[ + + ]
609 [ + - ][ + - ]: 72 : && aDateTimeUtc.GetYear() != TIMESTAMP_INVALID_DATETIME.GetYear() ) {
[ + - ][ + - ]
[ + - ][ # #
# # # # ]
610 [ + - ]: 21 : aDateTimeUtc.ConvertToUTC();
611 : : }
612 : : sal_uInt32 nLower, nUpper;
613 [ + - ]: 36 : aDateTimeUtc.GetWin32FileDateTime( nLower, nUpper );
614 [ + - ][ + - ]: 36 : rStrm << nLower << nUpper;
615 : 36 : }
616 : :
617 : 0 : SfxOleDateProperty::SfxOleDateProperty( sal_Int32 nPropId ) :
618 : 0 : SfxOlePropertyBase( nPropId, PROPTYPE_DATE )
619 : : {
620 : 0 : }
621 : :
622 : 0 : void SfxOleDateProperty::ImplLoad( SvStream& rStrm )
623 : : {
624 : 0 : double fValue(0.0);
625 [ # # ]: 0 : rStrm >> fValue;
626 : : //stored as number of days (not seconds) since December 31, 1899
627 : 0 : ::Date aDate(31, 12, 1899);
628 : 0 : long nDays = fValue;
629 [ # # ]: 0 : aDate += nDays;
630 : 0 : maDate.Day = aDate.GetDay();
631 : 0 : maDate.Month = aDate.GetMonth();
632 : 0 : maDate.Year = aDate.GetYear();
633 : 0 : }
634 : :
635 : 0 : void SfxOleDateProperty::ImplSave( SvStream& rStrm )
636 : : {
637 [ # # ]: 0 : long nDays = ::Date::DateToDays(maDate.Day, maDate.Month, maDate.Year);
638 : : //number of days (not seconds) since December 31, 1899
639 [ # # ]: 0 : long nStartDays = ::Date::DateToDays(31, 12, 1899);
640 : 0 : double fValue = nDays-nStartDays;
641 [ # # ]: 0 : rStrm << fValue;
642 : 0 : }
643 : :
644 : : // ----------------------------------------------------------------------------
645 : :
646 : 0 : SfxOleThumbnailProperty::SfxOleThumbnailProperty(
647 : : sal_Int32 nPropId, const uno::Sequence<sal_uInt8> & i_rData) :
648 : : SfxOlePropertyBase( nPropId, PROPTYPE_CLIPFMT ),
649 [ # # ]: 0 : mData(i_rData)
650 : : {
651 : 0 : }
652 : :
653 : 0 : void SfxOleThumbnailProperty::ImplLoad( SvStream& )
654 : : {
655 : : SAL_WARN( "sfx2.doc", "SfxOleThumbnailProperty::ImplLoad - not implemented" );
656 : 0 : SetError( SVSTREAM_INVALID_ACCESS );
657 : 0 : }
658 : :
659 : 0 : void SfxOleThumbnailProperty::ImplSave( SvStream& rStrm )
660 : : {
661 : : /* Type Contents
662 : : -----------------------------------------------------------------------
663 : : int32 size of following data
664 : : int32 clipboard format tag (see below)
665 : : byte[] clipboard data (see below)
666 : :
667 : : Clipboard format tag:
668 : : -1 = Windows clipboard format
669 : : -2 = Macintosh clipboard format
670 : : -3 = GUID that contains a format identifier (FMTID)
671 : : >0 = custom clipboard format name plus data (see msdn site below)
672 : : 0 = no data
673 : :
674 : : References:
675 : : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/stg/stg/propvariant.asp
676 : : http://jakarta.apache.org/poi/hpsf/thumbnails.html
677 : : http://linux.com.hk/docs/poi/org/apache/poi/hpsf/Thumbnail.html
678 : : http://sparks.discreet.com/knowledgebase/public/solutions/ExtractThumbnailImg.htm
679 : : */
680 [ # # ]: 0 : if( IsValid() )
681 : : {
682 : : // clipboard size: clip_format_tag + data_format_tag + bitmap_len
683 : 0 : sal_Int32 nClipSize = static_cast< sal_Int32 >( 4 + 4 + mData.getLength() );
684 : 0 : rStrm << nClipSize << CLIPFMT_WIN << CLIPDATAFMT_DIB;
685 : 0 : rStrm.Write( mData.getConstArray(), mData.getLength() );
686 : : }
687 : : else
688 : : {
689 : : SAL_WARN( "sfx2.doc", "SfxOleThumbnailProperty::ImplSave - invalid thumbnail property" );
690 : 0 : SetError( SVSTREAM_INVALID_ACCESS );
691 : : }
692 : 0 : }
693 : :
694 : : // ----------------------------------------------------------------------------
695 : :
696 : 0 : SfxOleBlobProperty::SfxOleBlobProperty( sal_Int32 nPropId,
697 : : const uno::Sequence<sal_uInt8> & i_rData) :
698 : : SfxOlePropertyBase( nPropId, PROPTYPE_BLOB ),
699 [ # # ]: 0 : mData(i_rData)
700 : : {
701 : 0 : }
702 : :
703 : 0 : void SfxOleBlobProperty::ImplLoad( SvStream& )
704 : : {
705 : : SAL_WARN( "sfx2.doc", "SfxOleBlobProperty::ImplLoad - not implemented" );
706 : 0 : SetError( SVSTREAM_INVALID_ACCESS );
707 : 0 : }
708 : :
709 : 0 : void SfxOleBlobProperty::ImplSave( SvStream& rStrm )
710 : : {
711 [ # # ]: 0 : if (IsValid()) {
712 : 0 : rStrm.Write( mData.getConstArray(), mData.getLength() );
713 : : } else {
714 : : SAL_WARN( "sfx2.doc", "SfxOleBlobProperty::ImplSave - invalid BLOB property" );
715 : 0 : SetError( SVSTREAM_INVALID_ACCESS );
716 : : }
717 : 0 : }
718 : :
719 : : // ----------------------------------------------------------------------------
720 : :
721 : 404 : SfxOleDictionaryProperty::SfxOleDictionaryProperty( const SfxOleTextEncoding& rTextEnc ) :
722 : : SfxOlePropertyBase( PROPID_DICTIONARY, 0 ),
723 [ + - ][ + - ]: 404 : SfxOleStringHelper( rTextEnc )
724 : : {
725 : 404 : }
726 : :
727 : 0 : const String& SfxOleDictionaryProperty::GetPropertyName( sal_Int32 nPropId ) const
728 : : {
729 [ # # ]: 0 : SfxOlePropNameMap::const_iterator aIt = maPropNameMap.find( nPropId );
730 [ # # ][ # # ]: 0 : return (aIt == maPropNameMap.end()) ? String::EmptyString() : aIt->second;
[ # # ][ # # ]
731 : : }
732 : :
733 : 0 : void SfxOleDictionaryProperty::SetPropertyName( sal_Int32 nPropId, const String& rPropName )
734 : : {
735 : 0 : maPropNameMap[ nPropId ] = rPropName;
736 : : // dictionary property contains number of pairs in property type field
737 : 0 : SetPropType( static_cast< sal_Int32 >( maPropNameMap.size() ) );
738 : 0 : }
739 : :
740 : 39 : void SfxOleDictionaryProperty::ImplLoad( SvStream& rStrm )
741 : : {
742 : : // dictionary property contains number of pairs in property type field
743 : 39 : sal_Int32 nNameCount = GetPropType();
744 : : // read property ID/name pairs
745 : 39 : maPropNameMap.clear();
746 [ + + ][ + - ]: 72 : for( sal_Int32 nIdx = 0; (nIdx < nNameCount) && (rStrm.GetErrorCode() == SVSTREAM_OK) && !rStrm.IsEof(); ++nIdx )
[ + - ][ + + ]
747 : : {
748 : 33 : sal_Int32 nPropId(0);
749 [ + - ]: 33 : rStrm >> nPropId;
750 : : // name always stored as byte string
751 [ + - ][ + - ]: 33 : maPropNameMap[ nPropId ] = LoadString8( rStrm );
[ + - ][ + - ]
752 : : }
753 : 39 : }
754 : :
755 : 0 : void SfxOleDictionaryProperty::ImplSave( SvStream& rStrm )
756 : : {
757 : : // write property ID/name pairs
758 [ # # ][ # # ]: 0 : for( SfxOlePropNameMap::const_iterator aIt = maPropNameMap.begin(), aEnd = maPropNameMap.end(); aIt != aEnd; ++aIt )
[ # # ][ # # ]
[ # # ]
759 : : {
760 [ # # ][ # # ]: 0 : rStrm << aIt->first;
761 : : // name always stored as byte string
762 [ # # ][ # # ]: 0 : SaveString8( rStrm, aIt->second );
763 : : }
764 : 0 : }
765 : :
766 : : // ----------------------------------------------------------------------------
767 : :
768 : 404 : SfxOleSection::SfxOleSection( bool bSupportsDict ) :
769 : : maDictProp( maCodePageProp ),
770 : : mnStartPos( 0 ),
771 [ + - ][ + - ]: 404 : mbSupportsDict( bSupportsDict )
[ + - ]
772 : : {
773 : 404 : }
774 : :
775 : 1812 : SfxOlePropertyRef SfxOleSection::GetProperty( sal_Int32 nPropId ) const
776 : : {
777 [ + - ]: 1812 : SfxOlePropertyRef xProp;
778 [ + - ]: 1812 : SfxOlePropMap::const_iterator aIt = maPropMap.find( nPropId );
779 [ + + ]: 1812 : if( aIt != maPropMap.end() )
780 [ + - ]: 1812 : xProp = aIt->second;
781 : 1812 : return xProp;
782 : : }
783 : :
784 : 0 : bool SfxOleSection::GetInt32Value( sal_Int32& rnValue, sal_Int32 nPropId ) const
785 : : {
786 [ # # ]: 0 : SfxOlePropertyRef xProp = GetProperty( nPropId );
787 : : const SfxOleInt32Property* pProp =
788 [ # # ]: 0 : dynamic_cast< const SfxOleInt32Property* >( xProp.get() );
789 [ # # ]: 0 : if( pProp )
790 : 0 : rnValue = pProp->GetValue();
791 [ # # ]: 0 : return pProp != 0;
792 : : }
793 : :
794 : 0 : bool SfxOleSection::GetDoubleValue( double& rfValue, sal_Int32 nPropId ) const
795 : : {
796 [ # # ]: 0 : SfxOlePropertyRef xProp = GetProperty( nPropId );
797 : : const SfxOleDoubleProperty* pProp =
798 [ # # ]: 0 : dynamic_cast< const SfxOleDoubleProperty* >( xProp.get() );
799 [ # # ]: 0 : if( pProp )
800 : 0 : rfValue = pProp->GetValue();
801 [ # # ]: 0 : return pProp != 0;
802 : : }
803 : :
804 : 0 : bool SfxOleSection::GetBoolValue( bool& rbValue, sal_Int32 nPropId ) const
805 : : {
806 [ # # ]: 0 : SfxOlePropertyRef xProp = GetProperty( nPropId );
807 : : const SfxOleBoolProperty* pProp =
808 [ # # ]: 0 : dynamic_cast< const SfxOleBoolProperty* >( xProp.get() );
809 [ # # ]: 0 : if( pProp )
810 : 0 : rbValue = pProp->GetValue();
811 [ # # ]: 0 : return pProp != 0;
812 : : }
813 : :
814 : 1208 : bool SfxOleSection::GetStringValue( String& rValue, sal_Int32 nPropId ) const
815 : : {
816 [ + - ]: 1208 : SfxOlePropertyRef xProp = GetProperty( nPropId );
817 : : const SfxOleStringPropertyBase* pProp =
818 [ + + ]: 1208 : dynamic_cast< const SfxOleStringPropertyBase* >( xProp.get() );
819 [ + + ]: 1208 : if( pProp )
820 [ + - ]: 710 : rValue = pProp->GetValue();
821 [ + - ]: 1208 : return pProp != 0;
822 : : }
823 : :
824 : 604 : bool SfxOleSection::GetFileTimeValue( util::DateTime& rValue, sal_Int32 nPropId ) const
825 : : {
826 [ + - ]: 604 : SfxOlePropertyRef xProp = GetProperty( nPropId );
827 : : const SfxOleFileTimeProperty* pProp =
828 [ + + ]: 604 : dynamic_cast< const SfxOleFileTimeProperty* >( xProp.get() );
829 [ + + ]: 604 : if( pProp )
830 : : {
831 [ + + ]: 458 : if ( pProp->GetValue() == TIMESTAMP_INVALID_UTILDATETIME )
832 : 78 : rValue = util::DateTime();
833 : : else
834 : 380 : rValue = pProp->GetValue();
835 : : }
836 [ + - ]: 604 : return pProp != 0;
837 : : }
838 : :
839 : 0 : bool SfxOleSection::GetDateValue( util::Date& rValue, sal_Int32 nPropId ) const
840 : : {
841 [ # # ]: 0 : SfxOlePropertyRef xProp = GetProperty( nPropId );
842 : : const SfxOleDateProperty* pProp =
843 [ # # ]: 0 : dynamic_cast< const SfxOleDateProperty* >( xProp.get() );
844 [ # # ]: 0 : if( pProp )
845 : : {
846 [ # # ]: 0 : if ( pProp->GetValue() == TIMESTAMP_INVALID_UTILDATE )
847 : 0 : rValue = util::Date();
848 : : else
849 : 0 : rValue = pProp->GetValue();
850 : : }
851 [ # # ]: 0 : return pProp != 0;
852 : : }
853 : :
854 : 60 : void SfxOleSection::SetProperty( SfxOlePropertyRef xProp )
855 : : {
856 [ + - ]: 60 : if( xProp.get() )
857 [ + - ][ + - ]: 60 : maPropMap[ xProp->GetPropId() ] = xProp;
858 : 60 : }
859 : :
860 : 0 : void SfxOleSection::SetInt32Value( sal_Int32 nPropId, sal_Int32 nValue )
861 : : {
862 [ # # ][ # # ]: 0 : SetProperty( SfxOlePropertyRef( new SfxOleInt32Property( nPropId, nValue ) ) );
863 : 0 : }
864 : :
865 : 0 : void SfxOleSection::SetDoubleValue( sal_Int32 nPropId, double fValue )
866 : : {
867 [ # # ][ # # ]: 0 : SetProperty( SfxOlePropertyRef( new SfxOleDoubleProperty( nPropId, fValue ) ) );
868 : 0 : }
869 : :
870 : 0 : void SfxOleSection::SetBoolValue( sal_Int32 nPropId, bool bValue )
871 : : {
872 [ # # ][ # # ]: 0 : SetProperty( SfxOlePropertyRef( new SfxOleBoolProperty( nPropId, bValue ) ) );
873 : 0 : }
874 : :
875 : 96 : bool SfxOleSection::SetStringValue( sal_Int32 nPropId, const String& rValue, bool bSkipEmpty )
876 : : {
877 [ + - ][ + + ]: 96 : bool bInserted = !bSkipEmpty || (rValue.Len() > 0);
878 [ + + ]: 96 : if( bInserted )
879 [ + - ][ + - ]: 24 : SetProperty( SfxOlePropertyRef( new SfxOleString8Property( nPropId, maCodePageProp, rValue ) ) );
880 : 96 : return bInserted;
881 : : }
882 : :
883 : 36 : void SfxOleSection::SetFileTimeValue( sal_Int32 nPropId, const util::DateTime& rValue )
884 : : {
885 [ + + ][ + - ]: 36 : if ( rValue.Year == 0 || rValue.Month == 0 || rValue.Day == 0 )
[ - + ]
886 [ + - ][ + - ]: 6 : SetProperty( SfxOlePropertyRef( new SfxOleFileTimeProperty( nPropId, TIMESTAMP_INVALID_UTILDATETIME ) ) );
[ + - ][ + - ]
[ + - ]
887 : : else
888 [ + - ][ + - ]: 30 : SetProperty( SfxOlePropertyRef( new SfxOleFileTimeProperty( nPropId, rValue ) ) );
889 : 36 : }
890 : :
891 : 0 : void SfxOleSection::SetDateValue( sal_Int32 nPropId, const util::Date& rValue )
892 : : {
893 : : //Annoyingly MS2010 considers VT_DATE apparently as an invalid possibility, so here we use VT_FILETIME
894 : : //instead :-(
895 [ # # ][ # # ]: 0 : if ( rValue.Year == 0 || rValue.Month == 0 || rValue.Day == 0 )
[ # # ]
896 [ # # ][ # # ]: 0 : SetProperty( SfxOlePropertyRef( new SfxOleFileTimeProperty( nPropId, TIMESTAMP_INVALID_UTILDATETIME ) ) );
[ # # ][ # # ]
[ # # ]
897 : : else
898 : : {
899 : 0 : const util::DateTime aValue(0, 0, 0, 0, rValue.Day, rValue.Month, rValue.Year );
900 [ # # ][ # # ]: 0 : SetProperty( SfxOlePropertyRef( new SfxOleFileTimeProperty( nPropId, aValue ) ) );
[ # # ][ # # ]
[ # # ]
901 : : }
902 : 0 : }
903 : :
904 : 0 : void SfxOleSection::SetThumbnailValue( sal_Int32 nPropId,
905 : : const uno::Sequence<sal_uInt8> & i_rData)
906 : : {
907 [ # # ][ # # ]: 0 : SfxOleThumbnailProperty* pThumbnail = new SfxOleThumbnailProperty( nPropId, i_rData );
908 [ # # ]: 0 : SfxOlePropertyRef xProp( pThumbnail ); // take ownership
909 [ # # ][ # # ]: 0 : if( pThumbnail->IsValid() )
910 [ # # ][ # # ]: 0 : SetProperty( xProp );
[ # # ][ # # ]
911 : 0 : }
912 : :
913 : 0 : void SfxOleSection::SetBlobValue( sal_Int32 nPropId,
914 : : const uno::Sequence<sal_uInt8> & i_rData)
915 : : {
916 [ # # ][ # # ]: 0 : SfxOleBlobProperty* pBlob( new SfxOleBlobProperty( nPropId, i_rData ) );
917 [ # # ]: 0 : SfxOlePropertyRef xProp( pBlob );
918 [ # # ][ # # ]: 0 : if( pBlob->IsValid() ) {
919 [ # # ][ # # ]: 0 : SetProperty( xProp );
[ # # ]
920 [ # # ]: 0 : }
921 : 0 : }
922 : :
923 : 0 : Any SfxOleSection::GetAnyValue( sal_Int32 nPropId ) const
924 : : {
925 : 0 : Any aValue;
926 : 0 : sal_Int32 nInt32 = 0;
927 : 0 : double fDouble = 0.0;
928 : 0 : bool bBool = false;
929 [ # # ]: 0 : String aString;
930 : 0 : ::com::sun::star::util::DateTime aApiDateTime;
931 : 0 : ::com::sun::star::util::Date aApiDate;
932 : :
933 [ # # ][ # # ]: 0 : if( GetInt32Value( nInt32, nPropId ) )
934 [ # # ]: 0 : aValue <<= nInt32;
935 [ # # ][ # # ]: 0 : else if( GetDoubleValue( fDouble, nPropId ) )
936 [ # # ]: 0 : aValue <<= fDouble;
937 [ # # ][ # # ]: 0 : else if( GetBoolValue( bBool, nPropId ) )
938 [ # # ][ # # ]: 0 : ::comphelper::setBOOL( aValue, bBool ? sal_True : sal_False );
939 [ # # ][ # # ]: 0 : else if( GetStringValue( aString, nPropId ) )
940 [ # # ][ # # ]: 0 : aValue <<= OUString( aString );
941 [ # # ][ # # ]: 0 : else if( GetFileTimeValue( aApiDateTime, nPropId ) )
942 : : {
943 [ # # ]: 0 : aValue <<= aApiDateTime;
944 : : }
945 [ # # ][ # # ]: 0 : else if( GetDateValue( aApiDate, nPropId ) )
946 : : {
947 [ # # ]: 0 : aValue <<= aApiDate;
948 : : }
949 [ # # ]: 0 : return aValue;
950 : : }
951 : :
952 : 24 : bool SfxOleSection::SetAnyValue( sal_Int32 nPropId, const Any& rValue )
953 : : {
954 : 24 : bool bInserted = true;
955 : 24 : sal_Int32 nInt32 = 0;
956 : 24 : double fDouble = 0.0;
957 : 24 : OUString aString;
958 : 24 : ::com::sun::star::util::DateTime aApiDateTime;
959 : 24 : ::com::sun::star::util::Date aApiDate;
960 : :
961 [ - + ][ + - ]: 24 : if( rValue.getValueType() == ::getBooleanCppuType() )
962 [ # # ][ # # ]: 0 : SetBoolValue( nPropId, ::comphelper::getBOOL( rValue ) == sal_True );
963 [ - + ]: 24 : else if( rValue >>= nInt32 )
964 [ # # ]: 0 : SetInt32Value( nPropId, nInt32 );
965 [ - + ]: 24 : else if( rValue >>= fDouble )
966 [ # # ]: 0 : SetDoubleValue( nPropId, fDouble );
967 [ + - ]: 24 : else if( rValue >>= aString )
968 [ + - ][ + - ]: 24 : bInserted = SetStringValue( nPropId, aString );
[ + - ]
969 [ # # ][ # # ]: 0 : else if( rValue >>= aApiDateTime )
970 [ # # ]: 0 : SetFileTimeValue( nPropId, aApiDateTime );
971 [ # # ][ # # ]: 0 : else if( rValue >>= aApiDate )
972 [ # # ]: 0 : SetDateValue( nPropId, aApiDate );
973 : : else
974 : 0 : bInserted = false;
975 : 24 : return bInserted;
976 : : }
977 : :
978 : 0 : const String& SfxOleSection::GetPropertyName( sal_Int32 nPropId ) const
979 : : {
980 : 0 : return maDictProp.GetPropertyName( nPropId );
981 : : }
982 : :
983 : 0 : void SfxOleSection::SetPropertyName( sal_Int32 nPropId, const String& rPropName )
984 : : {
985 : 0 : maDictProp.SetPropertyName( nPropId, rPropName );
986 : 0 : }
987 : :
988 : 72 : void SfxOleSection::GetPropertyIds( ::std::vector< sal_Int32 >& rPropIds ) const
989 : : {
990 : 72 : rPropIds.clear();
991 [ - + ]: 72 : for( SfxOlePropMap::const_iterator aIt = maPropMap.begin(), aEnd = maPropMap.end(); aIt != aEnd; ++aIt )
992 [ # # ]: 0 : rPropIds.push_back( aIt->first );
993 : 72 : }
994 : :
995 : 24 : sal_Int32 SfxOleSection::GetFreePropertyId() const
996 : : {
997 [ + - ][ # # ]: 24 : return maPropMap.empty() ? PROPID_FIRSTCUSTOM : (maPropMap.rbegin()->first + 1);
[ - + ][ # # ]
998 : : }
999 : :
1000 : 377 : void SfxOleSection::ImplLoad( SvStream& rStrm )
1001 : : {
1002 : : // read section header
1003 : 377 : mnStartPos = rStrm.Tell();
1004 : 377 : sal_uInt32 nSize(0);
1005 : 377 : sal_Int32 nPropCount(0);
1006 [ + - ][ + - ]: 377 : rStrm >> nSize >> nPropCount;
1007 : :
1008 : : // read property ID/position pairs
1009 : : typedef ::std::map< sal_Int32, sal_uInt32 > SfxOlePropPosMap;
1010 [ + - ]: 377 : SfxOlePropPosMap aPropPosMap;
1011 [ + + ][ + - ]: 3565 : for( sal_Int32 nPropIdx = 0; (nPropIdx < nPropCount) && (rStrm.GetErrorCode() == SVSTREAM_OK) && !rStrm.IsEof(); ++nPropIdx )
[ + - ][ + + ]
1012 : : {
1013 : 3188 : sal_Int32 nPropId(0);
1014 : 3188 : sal_uInt32 nPropPos(0);
1015 [ + - ][ + - ]: 3188 : rStrm >> nPropId >> nPropPos;
1016 [ + - ]: 3188 : aPropPosMap[ nPropId ] = nPropPos;
1017 : : }
1018 : :
1019 : : // read codepage property
1020 [ + - ]: 377 : SfxOlePropPosMap::iterator aCodePageIt = aPropPosMap.find( PROPID_CODEPAGE );
1021 [ + - ][ + + ]: 377 : if( (aCodePageIt != aPropPosMap.end()) && SeekToPropertyPos( rStrm, aCodePageIt->second ) )
[ + - ][ + - ]
[ + - ][ + - ]
[ + + # # ]
1022 : : {
1023 : : // codepage property must be of type signed int-16
1024 : 359 : sal_Int32 nPropType(0);
1025 [ + - ]: 359 : rStrm >> nPropType;
1026 [ + - ]: 359 : if( nPropType == PROPTYPE_INT16 )
1027 [ + - ]: 359 : LoadObject( rStrm, maCodePageProp );
1028 : : // remove property position
1029 [ + - ]: 359 : aPropPosMap.erase( aCodePageIt );
1030 : : }
1031 : :
1032 : : // read dictionary property
1033 [ + - ]: 377 : SfxOlePropPosMap::iterator aDictIt = aPropPosMap.find( PROPID_DICTIONARY );
1034 [ + - ][ + + ]: 377 : if( (aDictIt != aPropPosMap.end()) && SeekToPropertyPos( rStrm, aDictIt->second ) )
[ + - ][ + - ]
[ + - ][ + - ]
[ + + # # ]
1035 : : {
1036 : : // #i66214# #i66428# applications may write broken dictionary properties in wrong sections
1037 [ + - ]: 39 : if( mbSupportsDict )
1038 : : {
1039 : : // dictionary property contains number of pairs in property type field
1040 : 39 : sal_Int32 nNameCount(0);
1041 [ + - ]: 39 : rStrm >> nNameCount;
1042 : 39 : maDictProp.SetNameCount( nNameCount );
1043 [ + - ]: 39 : LoadObject( rStrm, maDictProp );
1044 : : }
1045 : : // always remove position of dictionary property (do not try to read it again below)
1046 [ + - ]: 39 : aPropPosMap.erase( aDictIt );
1047 : : }
1048 : :
1049 : : // read other properties
1050 : 377 : maPropMap.clear();
1051 [ + - ][ + - ]: 3167 : for( SfxOlePropPosMap::const_iterator aIt = aPropPosMap.begin(), aEnd = aPropPosMap.end(); aIt != aEnd; ++aIt )
[ + - ][ + + ]
[ + - ]
1052 [ + - ][ + - ]: 2790 : if( SeekToPropertyPos( rStrm, aIt->second ) )
[ + - ]
1053 [ + - ][ + - ]: 3167 : LoadProperty( rStrm, aIt->first );
1054 : 377 : }
1055 : :
1056 : 27 : void SfxOleSection::ImplSave( SvStream& rStrm )
1057 : : {
1058 : : /* Always export with UTF-8 encoding. All dependent properties (bytestring
1059 : : and dictionary) will be updated automatically. */
1060 [ + - ]: 27 : maCodePageProp.SetTextEncoding( RTL_TEXTENCODING_UTF8 );
1061 : :
1062 : : // write section header
1063 : 27 : mnStartPos = rStrm.Tell();
1064 : 27 : sal_Int32 nPropCount = static_cast< sal_Int32 >( maPropMap.size() + 1 );
1065 [ - + ]: 27 : if( maDictProp.HasPropertyNames() )
1066 : 0 : ++nPropCount;
1067 [ + - ][ + - ]: 27 : rStrm << sal_uInt32( 0 ) << nPropCount;
1068 : :
1069 : : // write placeholders for property ID/position pairs
1070 : 27 : sal_Size nPropPosPos = rStrm.Tell();
1071 [ + - ]: 27 : rStrm.SeekRel( static_cast< sal_sSize >( 8 * nPropCount ) );
1072 : :
1073 : : // write dictionary property
1074 [ - + ]: 27 : if( maDictProp.HasPropertyNames() )
1075 [ # # ]: 0 : SaveProperty( rStrm, maDictProp, nPropPosPos );
1076 : : // write codepage property
1077 [ + - ]: 27 : SaveProperty( rStrm, maCodePageProp, nPropPosPos );
1078 : : // write other properties
1079 [ + + ]: 87 : for( SfxOlePropMap::const_iterator aIt = maPropMap.begin(), aEnd = maPropMap.end(); aIt != aEnd; ++aIt )
1080 [ + - ]: 60 : SaveProperty( rStrm, *aIt->second, nPropPosPos );
1081 : :
1082 : : // write section size (first field in section header)
1083 [ + - ]: 27 : rStrm.Seek( STREAM_SEEK_TO_END );
1084 : 27 : sal_uInt32 nSectSize = static_cast< sal_uInt32 >( rStrm.Tell() - mnStartPos );
1085 [ + - ]: 27 : rStrm.Seek( mnStartPos );
1086 [ + - ]: 27 : rStrm << nSectSize;
1087 : 27 : }
1088 : :
1089 : 3188 : bool SfxOleSection::SeekToPropertyPos( SvStream& rStrm, sal_uInt32 nPropPos ) const
1090 : : {
1091 : 3188 : rStrm.Seek( static_cast< sal_Size >( mnStartPos + nPropPos ) );
1092 : 3188 : return rStrm.GetErrorCode() == SVSTREAM_OK;
1093 : : }
1094 : :
1095 : 2790 : void SfxOleSection::LoadProperty( SvStream& rStrm, sal_Int32 nPropId )
1096 : : {
1097 : : // property data type
1098 : 2790 : sal_Int32 nPropType(0);
1099 [ + - ]: 2790 : rStrm >> nPropType;
1100 : : // create empty property object
1101 [ + - ]: 2790 : SfxOlePropertyRef xProp;
1102 [ + - + + : 2790 : switch( nPropType )
- + - + ]
1103 : : {
1104 : : case PROPTYPE_INT32:
1105 [ + - ][ + - ]: 707 : xProp.reset( new SfxOleInt32Property( nPropId ) );
[ + - ]
1106 : 707 : break;
1107 : : case PROPTYPE_DOUBLE:
1108 [ # # ][ # # ]: 0 : xProp.reset( new SfxOleDoubleProperty( nPropId ) );
[ # # ]
1109 : 0 : break;
1110 : : case PROPTYPE_BOOL:
1111 [ + - ][ + - ]: 436 : xProp.reset( new SfxOleBoolProperty( nPropId ) );
[ + - ]
1112 : 436 : break;
1113 : : case PROPTYPE_STRING8:
1114 [ + - ][ + - ]: 917 : xProp.reset( new SfxOleString8Property( nPropId, maCodePageProp ) );
[ + - ]
1115 : 917 : break;
1116 : : case PROPTYPE_STRING16:
1117 [ # # ][ # # ]: 0 : xProp.reset( new SfxOleString16Property( nPropId ) );
[ # # ]
1118 : 0 : break;
1119 : : case PROPTYPE_FILETIME:
1120 [ + - ][ + - ]: 458 : xProp.reset( new SfxOleFileTimeProperty( nPropId ) );
[ + - ]
1121 : 458 : break;
1122 : : case PROPTYPE_DATE:
1123 [ # # ][ # # ]: 0 : xProp.reset( new SfxOleDateProperty( nPropId ) );
[ # # ]
1124 : 0 : break;
1125 : : }
1126 : : // load property contents
1127 [ + + ]: 2790 : if( xProp.get() )
1128 : : {
1129 [ + - ]: 2518 : SetError( xProp->Load( rStrm ) );
1130 [ + - ][ + - ]: 2518 : maPropMap[ nPropId ] = xProp;
1131 [ + - ]: 2790 : }
1132 : 2790 : }
1133 : :
1134 : 87 : void SfxOleSection::SaveProperty( SvStream& rStrm, SfxOlePropertyBase& rProp, sal_Size& rnPropPosPos )
1135 : : {
1136 : 87 : rStrm.Seek( STREAM_SEEK_TO_END );
1137 : 87 : sal_uInt32 nPropPos = static_cast< sal_uInt32 >( rStrm.Tell() - mnStartPos );
1138 : : // property data type
1139 : 87 : rStrm << rProp.GetPropType();
1140 : : // write property contents
1141 : 87 : SaveObject( rStrm, rProp );
1142 : : // align to 32-bit
1143 [ + + ]: 165 : while( (rStrm.Tell() & 3) != 0 )
1144 : 78 : rStrm << sal_uInt8( 0 );
1145 : : // write property ID/position pair
1146 : 87 : rStrm.Seek( rnPropPosPos );
1147 : 87 : rStrm << rProp.GetPropId() << nPropPos;
1148 : 87 : rnPropPosPos = rStrm.Tell();
1149 : 87 : }
1150 : :
1151 : : // ----------------------------------------------------------------------------
1152 : :
1153 : 338 : ErrCode SfxOlePropertySet::LoadPropertySet( SotStorage* pStrg, const String& rStrmName )
1154 : : {
1155 [ + - ]: 338 : if( pStrg )
1156 : : {
1157 [ + - ]: 338 : SotStorageStreamRef xStrm = pStrg->OpenSotStream( rStrmName, STREAM_STD_READ );
1158 [ + + ][ + + ]: 338 : if( xStrm.Is() && (xStrm->GetError() == SVSTREAM_OK) )
[ + - ]
1159 : : {
1160 [ + - ]: 305 : xStrm->SetBufferSize( STREAM_BUFFER_SIZE );
1161 [ + - ]: 305 : Load( *xStrm );
1162 : : }
1163 : : else
1164 [ + - ]: 338 : SetError( ERRCODE_IO_ACCESSDENIED );
1165 : : }
1166 : : else
1167 : 0 : SetError( ERRCODE_IO_ACCESSDENIED );
1168 : 338 : return GetError();
1169 : : }
1170 : :
1171 : 18 : ErrCode SfxOlePropertySet::SavePropertySet( SotStorage* pStrg, const String& rStrmName )
1172 : : {
1173 [ + - ]: 18 : if( pStrg )
1174 : : {
1175 [ + - ]: 18 : SotStorageStreamRef xStrm = pStrg->OpenSotStream( rStrmName, STREAM_TRUNC | STREAM_STD_WRITE );
1176 [ + - ]: 18 : if( xStrm.Is() )
1177 [ + - ]: 18 : Save( *xStrm );
1178 : : else
1179 [ + - ]: 18 : SetError( ERRCODE_IO_ACCESSDENIED );
1180 : : }
1181 : : else
1182 : 0 : SetError( ERRCODE_IO_ACCESSDENIED );
1183 : 18 : return GetError();
1184 : : }
1185 : :
1186 : 338 : SfxOleSectionRef SfxOlePropertySet::GetSection( SfxOleSectionType eSection ) const
1187 : : {
1188 : 338 : return GetSection( GetSectionGuid( eSection ) );
1189 : : }
1190 : :
1191 : 742 : SfxOleSectionRef SfxOlePropertySet::GetSection( const SvGlobalName& rSectionGuid ) const
1192 : : {
1193 [ + - ]: 742 : SfxOleSectionRef xSection;
1194 [ + - ]: 742 : SfxOleSectionMap::const_iterator aIt = maSectionMap.find( rSectionGuid );
1195 [ + + ]: 742 : if( aIt != maSectionMap.end() )
1196 [ + - ]: 742 : xSection = aIt->second;
1197 : 742 : return xSection;
1198 : : }
1199 : :
1200 : 27 : SfxOleSection& SfxOlePropertySet::AddSection( SfxOleSectionType eSection )
1201 : : {
1202 : 27 : return AddSection( GetSectionGuid( eSection ) );
1203 : : }
1204 : :
1205 : 404 : SfxOleSection& SfxOlePropertySet::AddSection( const SvGlobalName& rSectionGuid )
1206 : : {
1207 [ + - ]: 404 : SfxOleSectionRef xSection = GetSection( rSectionGuid );
1208 [ + - ]: 404 : if( !xSection )
1209 : : {
1210 : : // #i66214# #i66428# applications may write broken dictionary properties in wrong sections
1211 [ + - ][ + - ]: 404 : bool bSupportsDict = rSectionGuid == GetSectionGuid( SECTION_CUSTOM );
1212 [ + - ][ + - ]: 404 : xSection.reset( new SfxOleSection( bSupportsDict ) );
[ + - ]
1213 [ + - ][ + - ]: 404 : maSectionMap[ rSectionGuid ] = xSection;
1214 : : }
1215 [ + - ]: 404 : return *xSection;
1216 : : }
1217 : :
1218 : 305 : void SfxOlePropertySet::ImplLoad( SvStream& rStrm )
1219 : : {
1220 : : // read property set header
1221 : : sal_uInt16 nByteOrder;
1222 : : sal_uInt16 nVersion;
1223 : : sal_uInt16 nOsMinor;
1224 : : sal_uInt16 nOsType;
1225 [ + - ]: 305 : SvGlobalName aGuid;
1226 : 305 : sal_Int32 nSectCount(0);
1227 [ + - ][ + - ]: 305 : rStrm >> nByteOrder >> nVersion >> nOsMinor >> nOsType >> aGuid >> nSectCount;
[ + - ][ + - ]
[ + - ][ + - ]
1228 : :
1229 : : // read sections
1230 : 305 : sal_Size nSectPosPos = rStrm.Tell();
1231 [ + + ][ + - ]: 682 : for( sal_Int32 nSectIdx = 0; (nSectIdx < nSectCount) && (rStrm.GetErrorCode() == SVSTREAM_OK) && !rStrm.IsEof(); ++nSectIdx )
[ + - ][ + + ]
1232 : : {
1233 : : // read section guid/position pair
1234 [ + - ]: 377 : rStrm.Seek( nSectPosPos );
1235 [ + - ]: 377 : SvGlobalName aSectGuid;
1236 : : sal_uInt32 nSectPos;
1237 [ + - ][ + - ]: 377 : rStrm >> aSectGuid >> nSectPos;
1238 : 377 : nSectPosPos = rStrm.Tell();
1239 : : // read section
1240 [ + - ]: 377 : rStrm.Seek( static_cast< sal_Size >( nSectPos ) );
1241 [ + - ]: 377 : if( rStrm.GetErrorCode() == SVSTREAM_OK )
1242 [ + - ][ + - ]: 377 : LoadObject( rStrm, AddSection( aSectGuid ) );
1243 [ + - ][ + - ]: 682 : }
1244 : 305 : }
1245 : :
1246 : 18 : void SfxOlePropertySet::ImplSave( SvStream& rStrm )
1247 : : {
1248 : : // write property set header
1249 [ + - ]: 18 : SvGlobalName aGuid;
1250 : 18 : sal_Int32 nSectCount = static_cast< sal_Int32 >( maSectionMap.size() );
1251 [ + - ]: 18 : rStrm << sal_uInt16( 0xFFFE ) // byte order
1252 [ + - ]: 18 : << sal_uInt16( 0 ) // version
1253 [ + - ]: 18 : << sal_uInt16( 1 ) // OS minor version
1254 [ + - ]: 18 : << sal_uInt16( 2 ) // OS type always windows for text encoding
1255 [ + - ]: 18 : << aGuid // unused guid
1256 [ + - ]: 18 : << nSectCount; // number of sections
1257 : :
1258 : : // write placeholders for section guid/position pairs
1259 : 18 : sal_Size nSectPosPos = rStrm.Tell();
1260 [ + - ]: 18 : rStrm.SeekRel( static_cast< sal_sSize >( 20 * nSectCount ) );
1261 : :
1262 : : // write sections
1263 [ + + ]: 45 : for( SfxOleSectionMap::const_iterator aIt = maSectionMap.begin(), aEnd = maSectionMap.end(); aIt != aEnd; ++aIt )
1264 : : {
1265 : 27 : SfxOleSection& rSection = *aIt->second;
1266 [ + - ]: 27 : rStrm.Seek( STREAM_SEEK_TO_END );
1267 : 27 : sal_uInt32 nSectPos = static_cast< sal_uInt32 >( rStrm.Tell() );
1268 : : // write the section
1269 [ + - ]: 27 : SaveObject( rStrm, rSection );
1270 : : // write section guid/position pair
1271 [ + - ]: 27 : rStrm.Seek( nSectPosPos );
1272 [ + - ][ + - ]: 27 : rStrm << aIt->first << nSectPos;
1273 : 27 : nSectPosPos = rStrm.Tell();
1274 [ + - ]: 18 : }
1275 : 18 : }
1276 : :
1277 : 769 : const SvGlobalName& SfxOlePropertySet::GetSectionGuid( SfxOleSectionType eSection )
1278 : : {
1279 [ + + ][ + - ]: 769 : static const SvGlobalName saGlobalGuid( 0xF29F85E0, 0x4FF9, 0x1068, 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 );
[ + - ][ # # ]
1280 [ + + ][ + - ]: 769 : static const SvGlobalName saBuiltInGuid( 0xD5CDD502, 0x2E9C, 0x101B, 0x93, 0x97, 0x08, 0x00, 0x2B, 0x2C, 0xF9, 0xAE );
[ + - ][ # # ]
1281 [ + + ][ + - ]: 769 : static const SvGlobalName saCustomGuid( 0xD5CDD505, 0x2E9C, 0x101B, 0x93, 0x97, 0x08, 0x00, 0x2B, 0x2C, 0xF9, 0xAE );
[ + - ][ # # ]
1282 [ + + ][ + - ]: 769 : static const SvGlobalName saEmptyGuid;
[ + - ][ # # ]
1283 [ + + + - ]: 769 : switch( eSection )
1284 : : {
1285 : 178 : case SECTION_GLOBAL: return saGlobalGuid;
1286 : 9 : case SECTION_BUILTIN: return saBuiltInGuid;
1287 : 582 : case SECTION_CUSTOM: return saCustomGuid;
1288 : : default: SAL_WARN( "sfx2.doc", "SfxOlePropertySet::GetSectionGuid - unknown section type" );
1289 : : }
1290 : 769 : return saEmptyGuid;
1291 : : }
1292 : :
1293 : : // ============================================================================
1294 : :
1295 : : //} // namespace
1296 : :
1297 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|