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