Kaydet (Commit) 5dcf5e9b authored tarafından Markus Mohrhard's avatar Markus Mohrhard

cache calls to Date::SYSTEM

Change-Id: Iccdfeb45519dfc7e1373bf1303ecfc0c83f4cbc0
üst 03949c87
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "rangelst.hxx" #include "rangelst.hxx"
#include <rtl/math.hxx> #include <rtl/math.hxx>
#include <tools/date.hxx>
#include <map> #include <map>
...@@ -375,9 +376,19 @@ public: ...@@ -375,9 +376,19 @@ public:
virtual void dumpInfo(rtl::OUStringBuffer& rBuf) const; virtual void dumpInfo(rtl::OUStringBuffer& rBuf) const;
#endif #endif
virtual void startRendering();
virtual void endRendering();
private: private:
condformat::ScCondFormatDateType meType; condformat::ScCondFormatDateType meType;
struct ScCondDateFormatCache
{
Date aCachedDate;
};
boost::scoped_ptr<ScCondDateFormatCache> mpCache;
rtl::OUString maStyleName; rtl::OUString maStyleName;
}; };
......
...@@ -1662,9 +1662,12 @@ bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const ...@@ -1662,9 +1662,12 @@ bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const
if(pBaseCell->GetCellType() != CELLTYPE_VALUE && pBaseCell->GetCellType() != CELLTYPE_FORMULA) if(pBaseCell->GetCellType() != CELLTYPE_VALUE && pBaseCell->GetCellType() != CELLTYPE_FORMULA)
return false; return false;
Date aActDate( Date::SYSTEM ); if( !mpCache )
mpCache->aCachedDate = Date( Date::SYSTEM );
const Date& rActDate = mpCache->aCachedDate;
SvNumberFormatter* pFormatter = mpDoc->GetFormatTable(); SvNumberFormatter* pFormatter = mpDoc->GetFormatTable();
long nCurrentDate = aActDate - *(pFormatter->GetNullDate()); long nCurrentDate = rActDate - *(pFormatter->GetNullDate());
double nVal = mpDoc->GetValue(rPos); double nVal = mpDoc->GetValue(rPos);
long nCellDate = (long) ::rtl::math::approxFloor(nVal); long nCellDate = (long) ::rtl::math::approxFloor(nVal);
...@@ -1690,57 +1693,57 @@ bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const ...@@ -1690,57 +1693,57 @@ bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const
return true; return true;
break; break;
case condformat::LASTWEEK: case condformat::LASTWEEK:
if( aActDate.GetYear() == aCellDate.GetYear() && aActDate.GetMonth() == aCellDate.GetMonth() ) if( rActDate.GetYear() == aCellDate.GetYear() && rActDate.GetMonth() == aCellDate.GetMonth() )
{ {
if( aActDate.GetWeekOfYear( SUNDAY ) == aCellDate.GetWeekOfYear( SUNDAY ) + 1 ) if( rActDate.GetWeekOfYear( SUNDAY ) == aCellDate.GetWeekOfYear( SUNDAY ) + 1 )
return true; return true;
} }
break; break;
case condformat::THISWEEK: case condformat::THISWEEK:
if( aActDate.GetYear() == aCellDate.GetYear() && aActDate.GetMonth() == aCellDate.GetMonth() ) if( rActDate.GetYear() == aCellDate.GetYear() && rActDate.GetMonth() == aCellDate.GetMonth() )
{ {
if( aActDate.GetWeekOfYear( SUNDAY ) == aCellDate.GetWeekOfYear( SUNDAY ) ) if( rActDate.GetWeekOfYear( SUNDAY ) == aCellDate.GetWeekOfYear( SUNDAY ) )
return true; return true;
} }
break; break;
case condformat::NEXTWEEK: case condformat::NEXTWEEK:
if( aActDate.GetYear() == aCellDate.GetYear() && aActDate.GetMonth() == aCellDate.GetMonth() ) if( rActDate.GetYear() == aCellDate.GetYear() && rActDate.GetMonth() == aCellDate.GetMonth() )
{ {
if( aActDate.GetWeekOfYear( SUNDAY ) == aCellDate.GetWeekOfYear( SUNDAY ) - 1 ) if( rActDate.GetWeekOfYear( SUNDAY ) == aCellDate.GetWeekOfYear( SUNDAY ) - 1 )
return true; return true;
} }
break; break;
case condformat::LASTMONTH: case condformat::LASTMONTH:
if( aActDate.GetYear() == aCellDate.GetYear() ) if( rActDate.GetYear() == aCellDate.GetYear() )
{ {
if( aActDate.GetMonth() == aCellDate.GetMonth() + 1) if( rActDate.GetMonth() == aCellDate.GetMonth() + 1)
return true; return true;
} }
break; break;
case condformat::THISMONTH: case condformat::THISMONTH:
if( aActDate.GetYear() == aCellDate.GetYear() ) if( rActDate.GetYear() == aCellDate.GetYear() )
{ {
if( aActDate.GetMonth() == aCellDate.GetMonth() ) if( rActDate.GetMonth() == aCellDate.GetMonth() )
return true; return true;
} }
break; break;
case condformat::NEXTMONTH: case condformat::NEXTMONTH:
if( aActDate.GetYear() == aCellDate.GetYear() ) if( rActDate.GetYear() == aCellDate.GetYear() )
{ {
if( aActDate.GetMonth() == aCellDate.GetMonth() - 1) if( rActDate.GetMonth() == aCellDate.GetMonth() - 1)
return true; return true;
} }
break; break;
case condformat::LASTYEAR: case condformat::LASTYEAR:
if( aActDate.GetYear() == aCellDate.GetYear() + 1 ) if( rActDate.GetYear() == aCellDate.GetYear() + 1 )
return true; return true;
break; break;
case condformat::THISYEAR: case condformat::THISYEAR:
if( aActDate.GetYear() == aCellDate.GetYear() ) if( rActDate.GetYear() == aCellDate.GetYear() )
return true; return true;
break; break;
case condformat::NEXTYEAR: case condformat::NEXTYEAR:
if( aActDate.GetYear() == aCellDate.GetYear() - 1 ) if( rActDate.GetYear() == aCellDate.GetYear() - 1 )
return true; return true;
break; break;
} }
...@@ -1791,6 +1794,16 @@ void ScCondDateFormatEntry::dumpInfo( rtl::OUStringBuffer& rBuffer ) const ...@@ -1791,6 +1794,16 @@ void ScCondDateFormatEntry::dumpInfo( rtl::OUStringBuffer& rBuffer ) const
rBuffer.append("Date Format"); rBuffer.append("Date Format");
} }
void ScCondDateFormatEntry::startRendering()
{
mpCache.reset();
}
void ScCondDateFormatEntry::endRendering()
{
mpCache.reset();
}
//------------------------------------------------------------------------ //------------------------------------------------------------------------
ScConditionalFormat::ScConditionalFormat(sal_uInt32 nNewKey, ScDocument* pDocument) : ScConditionalFormat::ScConditionalFormat(sal_uInt32 nNewKey, ScDocument* pDocument) :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment