summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-08-09 15:46:57 +0100
committerCaolán McNamara <caolanm@redhat.com>2011-08-09 15:48:12 +0100
commit708f8c2373df89e6d267abe23d18e95f77e0036f (patch)
tree2c31d2e78aafc128e165874857db477feb9b4f3b /sfx2
parentb3a2205527b969128438bec50531e57c2efe9a32 (diff)
Resolves: fdo#38981 implement saving/loading PROPVARIANT::DATE ole2 property
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/doc/oleprops.cxx99
-rw-r--r--sfx2/source/doc/oleprops.hxx8
2 files changed, 104 insertions, 3 deletions
diff --git a/sfx2/source/doc/oleprops.cxx b/sfx2/source/doc/oleprops.cxx
index 6170d9120d20..3168c12db344 100644
--- a/sfx2/source/doc/oleprops.cxx
+++ b/sfx2/source/doc/oleprops.cxx
@@ -54,6 +54,7 @@ using namespace ::com::sun::star;
#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.
#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.
+#define TIMESTAMP_INVALID_UTILDATE ( util::Date ( 1, 1, 1601 ) ) /// Invalid value for date to create invalid instance of TimeStamp.
static
bool operator==(const util::DateTime &i_rLeft, const util::DateTime &i_rRight)
@@ -67,6 +68,14 @@ bool operator==(const util::DateTime &i_rLeft, const util::DateTime &i_rRight)
&& i_rLeft.HundredthSeconds == i_rRight.HundredthSeconds;
}
+static
+bool operator==(const util::Date &i_rLeft, const util::Date &i_rRight)
+{
+ return i_rLeft.Year == i_rRight.Year
+ && i_rLeft.Month == i_rRight.Month
+ && i_rLeft.Day == i_rRight.Day;
+}
+
// ============================================================================
/** Property representing a signed 32-bit integer value. */
@@ -204,6 +213,27 @@ private:
util::DateTime maDateTime;
};
+/** Property representing a filetime value as defined by the Windows API. */
+class SfxOleDateProperty : public SfxOlePropertyBase
+{
+public:
+ explicit SfxOleDateProperty( sal_Int32 nPropId );
+ /** @param rDate Date as LOCAL time. */
+ explicit SfxOleDateProperty( sal_Int32 nPropId, const util::Date& rDate );
+
+ /** Returns the date value as LOCAL time. */
+ inline const util::Date& GetValue() const { return maDate; }
+ /** @param rDate Date as LOCAL time. */
+ inline void SetValue( const util::Date& rDate ) { maDate = rDate; }
+
+private:
+ virtual void ImplLoad( SvStream& rStrm );
+ virtual void ImplSave( SvStream& rStrm );
+
+private:
+ util::Date maDate;
+};
+
// ============================================================================
/** Property representing a thumbnail picture.
@@ -615,6 +645,39 @@ void SfxOleFileTimeProperty::ImplSave( SvStream& rStrm )
rStrm << nLower << nUpper;
}
+SfxOleDateProperty::SfxOleDateProperty( sal_Int32 nPropId ) :
+ SfxOlePropertyBase( nPropId, PROPTYPE_DATE )
+{
+}
+
+SfxOleDateProperty::SfxOleDateProperty( sal_Int32 nPropId, const util::Date& rDate ) :
+ SfxOlePropertyBase( nPropId, PROPTYPE_DATE ),
+ maDate( rDate )
+{
+}
+
+void SfxOleDateProperty::ImplLoad( SvStream& rStrm )
+{
+ double fValue(0.0);
+ rStrm >> fValue;
+ //stored as number of days (not seconds) since December 31, 1899
+ ::Date aDate(31, 12, 1899);
+ long nDays = fValue;
+ aDate += nDays;
+ maDate.Day = aDate.GetDay();
+ maDate.Month = aDate.GetMonth();
+ maDate.Year = aDate.GetYear();
+}
+
+void SfxOleDateProperty::ImplSave( SvStream& rStrm )
+{
+ long nDays = ::Date::DateToDays(maDate.Day, maDate.Month, maDate.Year);
+ //number of days (not seconds) since December 31, 1899
+ long nStartDays = ::Date::DateToDays(31, 12, 1899);
+ double fValue = nDays-nStartDays;
+ rStrm << fValue;
+}
+
// ----------------------------------------------------------------------------
SfxOleThumbnailProperty::SfxOleThumbnailProperty(
@@ -810,6 +873,21 @@ bool SfxOleSection::GetFileTimeValue( util::DateTime& rValue, sal_Int32 nPropId
return pProp != 0;
}
+bool SfxOleSection::GetDateValue( util::Date& rValue, sal_Int32 nPropId ) const
+{
+ SfxOlePropertyRef xProp = GetProperty( nPropId );
+ const SfxOleDateProperty* pProp =
+ dynamic_cast< const SfxOleDateProperty* >( xProp.get() );
+ if( pProp )
+ {
+ if ( pProp->GetValue() == TIMESTAMP_INVALID_UTILDATE )
+ rValue = util::Date();
+ else
+ rValue = pProp->GetValue();
+ }
+ return pProp != 0;
+}
+
void SfxOleSection::SetProperty( SfxOlePropertyRef xProp )
{
if( xProp.get() )
@@ -847,6 +925,14 @@ void SfxOleSection::SetFileTimeValue( sal_Int32 nPropId, const util::DateTime& r
SetProperty( SfxOlePropertyRef( new SfxOleFileTimeProperty( nPropId, rValue ) ) );
}
+void SfxOleSection::SetDateValue( sal_Int32 nPropId, const util::Date& rValue )
+{
+ if ( rValue.Year == 0 || rValue.Month == 0 || rValue.Day == 0 )
+ SetProperty( SfxOlePropertyRef( new SfxOleDateProperty( nPropId, TIMESTAMP_INVALID_UTILDATE ) ) );
+ else
+ SetProperty( SfxOlePropertyRef( new SfxOleDateProperty( nPropId, rValue ) ) );
+}
+
void SfxOleSection::SetThumbnailValue( sal_Int32 nPropId,
const uno::Sequence<sal_uInt8> & i_rData)
{
@@ -874,6 +960,7 @@ Any SfxOleSection::GetAnyValue( sal_Int32 nPropId ) const
bool bBool = false;
String aString;
::com::sun::star::util::DateTime aApiDateTime;
+ ::com::sun::star::util::Date aApiDate;
if( GetInt32Value( nInt32, nPropId ) )
aValue <<= nInt32;
@@ -887,6 +974,10 @@ Any SfxOleSection::GetAnyValue( sal_Int32 nPropId ) const
{
aValue <<= aApiDateTime;
}
+ else if( GetDateValue( aApiDate, nPropId ) )
+ {
+ aValue <<= aApiDate;
+ }
return aValue;
}
@@ -897,6 +988,7 @@ bool SfxOleSection::SetAnyValue( sal_Int32 nPropId, const Any& rValue )
double fDouble = 0.0;
OUString aString;
::com::sun::star::util::DateTime aApiDateTime;
+ ::com::sun::star::util::Date aApiDate;
if( rValue.getValueType() == ::getBooleanCppuType() )
SetBoolValue( nPropId, ::comphelper::getBOOL( rValue ) == sal_True );
@@ -907,9 +999,9 @@ bool SfxOleSection::SetAnyValue( sal_Int32 nPropId, const Any& rValue )
else if( rValue >>= aString )
bInserted = SetStringValue( nPropId, aString );
else if( rValue >>= aApiDateTime )
- {
SetFileTimeValue( nPropId, aApiDateTime );
- }
+ else if( rValue >>= aApiDate )
+ SetDateValue( nPropId, aApiDate );
else
bInserted = false;
return bInserted;
@@ -1059,6 +1151,9 @@ void SfxOleSection::LoadProperty( SvStream& rStrm, sal_Int32 nPropId )
case PROPTYPE_FILETIME:
xProp.reset( new SfxOleFileTimeProperty( nPropId ) );
break;
+ case PROPTYPE_DATE:
+ xProp.reset( new SfxOleDateProperty( nPropId ) );
+ break;
}
// load property contents
if( xProp.get() )
diff --git a/sfx2/source/doc/oleprops.hxx b/sfx2/source/doc/oleprops.hxx
index 7e441a7e8909..85337322eb40 100644
--- a/sfx2/source/doc/oleprops.hxx
+++ b/sfx2/source/doc/oleprops.hxx
@@ -32,6 +32,7 @@
#include <vcl/bitmapex.hxx>
#include <com/sun/star/util/DateTime.hpp>
+#include <com/sun/star/util/Date.hpp>
// ============================================================================
@@ -299,12 +300,15 @@ public:
/** Returns the value of a time stamp property with the passed ID in rValue.
@return true = Property found, rValue is valid; false = Property not found. */
bool GetFileTimeValue( ::com::sun::star::util::DateTime& rValue, sal_Int32 nPropId ) const;
+ /** Returns the value of a date property with the passed ID in rValue.
+ @return true = Property found, rValue is valid; false = Property not found. */
+ bool GetDateValue( ::com::sun::star::util::Date& rValue, sal_Int32 nPropId ) const;
/** Adds the passed property to the property set. Drops an existing old property. */
void SetProperty( SfxOlePropertyRef xProp );
/** Inserts a signed int32 property with the passed value. */
void SetInt32Value( sal_Int32 nPropId, sal_Int32 nValue );
- /** Inserts a foating-point property with the passed value. */
+ /** Inserts a floating-point property with the passed value. */
void SetDoubleValue( sal_Int32 nPropId, double fValue );
/** Inserts a boolean property with the passed value. */
void SetBoolValue( sal_Int32 nPropId, bool bValue );
@@ -313,6 +317,8 @@ public:
bool SetStringValue( sal_Int32 nPropId, const String& rValue, bool bSkipEmpty = true );
/** Inserts a time stamp property with the passed value. */
void SetFileTimeValue( sal_Int32 nPropId, const ::com::sun::star::util::DateTime& rValue );
+ /** Inserts a date property with the passed value. */
+ void SetDateValue( sal_Int32 nPropId, const ::com::sun::star::util::Date& rValue );
/** Inserts a thumbnail property from the passed meta file. */
void SetThumbnailValue( sal_Int32 nPropId,
const ::com::sun::star::uno::Sequence<sal_uInt8> & i_rData);