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

initial work for date conditional formats

Change-Id: Ifba8a4061e898a031004c20222e78eb825f07e4e
üst ced69036
......@@ -95,7 +95,8 @@ enum ScFormatEntryType
CONDITION,
COLORSCALE,
DATABAR,
ICONSET
ICONSET,
DATE
};
}
......@@ -324,6 +325,59 @@ protected:
virtual void DataChanged( const ScRange* pModified ) const;
};
namespace condformat {
enum ScCondFormatDateType
{
YESTERDAY,
TOMORROW,
TODAY,
LAST7DAYS,
LASTWEEK,
THISWEEK,
NEXTWEEK,
LASTMONTH,
THISMONTH,
NEXTMONTH
};
}
class SC_DLLPUBLIC ScCondDateFormatEntry : public ScFormatEntry
{
public:
ScCondDateFormatEntry(ScDocument* pDoc);
ScCondDateFormatEntry(ScDocument* pDoc, const ScCondDateFormatEntry& rEntry);
bool IsValid( const ScAddress& rPos ) const;
void SetDateType(condformat::ScCondFormatDateType eType);
condformat::ScCondFormatDateType GetDateType() const;
const rtl::OUString& GetStyleName() const;
void SetStyleName( const rtl::OUString& rStyleName );
virtual condformat::ScFormatEntryType GetType() const { return condformat::DATE; }
virtual void UpdateReference( UpdateRefMode, const ScRange&,
SCsCOL, SCsROW, SCsTAB ) {}
virtual void UpdateMoveTab( SCTAB, SCTAB ) {}
virtual ScFormatEntry* Clone( ScDocument* pDoc = NULL ) const;
virtual void SetParent( ScConditionalFormat* ) {}
bool operator==( const ScFormatEntry& ) const;
#if DUMP_FORMAT_INFO
virtual void dumpInfo(rtl::OUStringBuffer& rBuf) const;
#endif
private:
condformat::ScCondFormatDateType meType;
rtl::OUString maStyleName;
};
//
// complete conditional formatting
//
......
......@@ -1628,6 +1628,101 @@ ScFormatEntry* ScCondFormatEntry::Clone( ScDocument* pDoc ) const
//------------------------------------------------------------------------
ScCondDateFormatEntry::ScCondDateFormatEntry( ScDocument* pDoc ):
ScFormatEntry( pDoc )
{
}
ScCondDateFormatEntry::ScCondDateFormatEntry( ScDocument* pDoc, const ScCondDateFormatEntry& rFormat ):
ScFormatEntry( pDoc ),
meType( rFormat.meType ),
maStyleName( rFormat.maStyleName )
{
}
bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const
{
ScBaseCell* pBaseCell = mpDoc->GetCell( rPos );
if(!pBaseCell)
return false;
if(pBaseCell->GetCellType() != CELLTYPE_VALUE && pBaseCell->GetCellType() != CELLTYPE_FORMULA)
return false;
double nVal = mpDoc->GetValue(rPos);
long nCellDate = static_cast<long>(nVal);
Date aActDate( Date::SYSTEM );
SvNumberFormatter* pFormatter = mpDoc->GetFormatTable();
long nCurrentDate = aActDate - *(pFormatter->GetNullDate());
switch(meType)
{
case condformat::TODAY:
if( nCurrentDate == nCellDate )
return true;
break;
case condformat::TOMORROW:
if( nCurrentDate == nCellDate -1 )
return true;
break;
case condformat::YESTERDAY:
if( nCurrentDate == nCellDate + 1)
return true;
break;
default:
return true;
break;
}
return false;
}
void ScCondDateFormatEntry::SetDateType( condformat::ScCondFormatDateType eType )
{
meType = eType;
}
condformat::ScCondFormatDateType ScCondDateFormatEntry::GetDateType() const
{
return meType;
}
const rtl::OUString& ScCondDateFormatEntry::GetStyleName() const
{
return maStyleName;
}
void ScCondDateFormatEntry::SetStyleName( const rtl::OUString& rStyleName )
{
maStyleName = rStyleName;
}
ScFormatEntry* ScCondDateFormatEntry::Clone( ScDocument* pDoc ) const
{
return new ScCondDateFormatEntry( pDoc, *this );
}
bool ScCondDateFormatEntry::operator==( const ScFormatEntry& r ) const
{
if(r.GetType() != condformat::DATE)
return false;
const ScCondDateFormatEntry& rEntry = static_cast<const ScCondDateFormatEntry&>(r);
if(rEntry.meType != meType)
return false;
return rEntry.maStyleName == maStyleName;
}
void ScCondDateFormatEntry::dumpInfo( rtl::OUStringBuffer& rBuffer ) const
{
rBuffer.append("Date Format");
}
//------------------------------------------------------------------------
ScConditionalFormat::ScConditionalFormat(sal_uInt32 nNewKey, ScDocument* pDocument) :
pDoc( pDocument ),
nKey( nNewKey )
......@@ -1717,6 +1812,12 @@ const rtl::OUString& ScConditionalFormat::GetCellStyle( ScBaseCell* pCell, const
if ( rEntry.IsCellValid( pCell, rPos ) )
return rEntry.GetStyle();
}
else if(itr->GetType() == condformat::DATE)
{
const ScCondDateFormatEntry& rEntry = static_cast<const ScCondDateFormatEntry&>(*itr);
if (rEntry.IsValid( rPos ))
return rEntry.GetStyleName();
}
}
return EMPTY_OUSTRING;
......@@ -1748,6 +1849,12 @@ ScCondFormatData ScConditionalFormat::GetData( ScBaseCell* pCell, const ScAddres
const ScIconSetFormat& rEntry = static_cast<const ScIconSetFormat&>(*itr);
aData.pIconSet = rEntry.GetIconSetInfo(rPos);
}
else if(itr->GetType() == condformat::DATE && aData.aStyleName.isEmpty())
{
const ScCondDateFormatEntry& rEntry = static_cast<const ScCondDateFormatEntry&>(*itr);
if ( rEntry.IsValid( rPos ) )
aData.aStyleName = rEntry.GetStyleName();
}
}
return aData;
}
......
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