[Libreoffice-commits] .: 6 commits - sc/inc sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Thu Nov 15 14:41:35 PST 2012
sc/inc/conditio.hxx | 77 +++++++++--
sc/inc/globstr.hrc | 5
sc/source/core/data/conditio.cxx | 173 ++++++++++++++++++++++++-
sc/source/filter/oox/condformatbuffer.cxx | 82 ++++++-----
sc/source/ui/condformat/condformatdlg.cxx | 12 +
sc/source/ui/condformat/condformatdlgentry.cxx | 145 +++++++++++++-------
sc/source/ui/condformat/condformathelper.cxx | 5
sc/source/ui/inc/condformatdlg.hrc | 2
sc/source/ui/inc/condformatdlgentry.hxx | 27 +++
sc/source/ui/inc/condformathelper.hxx | 3
sc/source/ui/src/condformatdlg.src | 25 +++
sc/source/ui/src/globstr.src | 4
12 files changed, 451 insertions(+), 109 deletions(-)
New commits:
commit 29206b09ca6bf2dfc5596b91fc80a0c1b62dcd6b
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Thu Nov 15 23:37:42 2012 +0100
ui part for conditional date formats
Change-Id: I96893aaa016e6947d354aac4d7bc88da693095da
diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index ea2d870..4fc17bd 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -612,9 +612,10 @@
#define STR_COND_ENDS_WITH 487
#define STR_COND_CONTAINS 488
#define STR_COND_NOT_CONTAINS 489
+#define STR_COND_DATE 490
-#define STR_ERR_CONDFORMAT_PROTECTED 490
+#define STR_ERR_CONDFORMAT_PROTECTED 491
-#define STR_COUNT 491
+#define STR_COUNT 492
#endif
diff --git a/sc/source/ui/condformat/condformatdlg.cxx b/sc/source/ui/condformat/condformatdlg.cxx
index 8ef887c..5212f62 100644
--- a/sc/source/ui/condformat/condformatdlg.cxx
+++ b/sc/source/ui/condformat/condformatdlg.cxx
@@ -91,6 +91,9 @@ ScCondFormatList::ScCondFormatList(Window* pParent, const ResId& rResId, ScDocum
break;
case condformat::ICONSET:
break;
+ case condformat::DATE:
+ maEntries.push_back(new ScDateFrmtEntry( this, mpDoc, static_cast<const ScCondDateFormatEntry*>( pEntry ) ) );
+ break;
}
}
}
@@ -249,6 +252,7 @@ IMPL_LINK(ScCondFormatList, TypeListHdl, ListBox*, pBox)
{
case condformat::entry::FORMULA:
case condformat::entry::CONDITION:
+ case condformat::entry::DATE:
break;
case condformat::entry::COLORSCALE2:
case condformat::entry::COLORSCALE3:
@@ -275,6 +279,14 @@ IMPL_LINK(ScCondFormatList, TypeListHdl, ListBox*, pBox)
static_cast<ScCondFormatDlg*>(GetParent())->InvalidateRefData();
itr->SetActive();
break;
+ case 3:
+ if(itr->GetType() == condformat::entry::DATE)
+ return 0;
+
+ maEntries.replace( itr, new ScDateFrmtEntry( this, mpDoc ));
+ static_cast<ScCondFormatDlg*>(GetParent())->InvalidateRefData();
+ itr->SetActive();
+ break;
}
RecalcAll();
return 0;
diff --git a/sc/source/ui/condformat/condformatdlgentry.cxx b/sc/source/ui/condformat/condformatdlgentry.cxx
index 817da0b..05e9335 100644
--- a/sc/source/ui/condformat/condformatdlgentry.cxx
+++ b/sc/source/ui/condformat/condformatdlgentry.cxx
@@ -254,7 +254,6 @@ ScConditionFrmtEntry::ScConditionFrmtEntry( Window* pParent, ScDocument* pDoc, c
void ScConditionFrmtEntry::Init()
{
- maLbStyle.SetSeparatorPos(0);
maEdVal1.SetGetFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeGetFocusHdl ) );
maEdVal2.SetGetFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeGetFocusHdl ) );
maEdVal1.SetLoseFocusHdl( LINK( GetParent()->GetParent(), ScCondFormatDlg, RangeLoseFocusHdl ) );
@@ -266,6 +265,7 @@ void ScConditionFrmtEntry::Init()
maEdVal1.SetModifyHdl( LINK( this, ScCondFrmtEntry, EdModifyHdl ) );
maEdVal2.SetModifyHdl( LINK( this, ScCondFrmtEntry, EdModifyHdl ) );
+ maLbStyle.SetSeparatorPos(0);
SfxStyleSheetIterator aStyleIter( mpDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() )
{
@@ -402,9 +402,11 @@ void ScConditionFrmtEntry::SetInactive()
Deselect();
}
-IMPL_LINK_NOARG(ScConditionFrmtEntry, StyleSelectHdl)
+namespace {
+
+void StyleSelect( ListBox& rLbStyle, ScDocument* pDoc, SvxFontPrevWindow& rWdPreview )
{
- if(maLbStyle.GetSelectEntryPos() == 0)
+ if(rLbStyle.GetSelectEntryPos() == 0)
{
// call new style dialog
SfxUInt16Item aFamilyItem( SID_STYLE_FAMILY, SFX_STYLE_FAMILY_PARA );
@@ -430,26 +432,32 @@ IMPL_LINK_NOARG(ScConditionFrmtEntry, StyleSelectHdl)
// Find the new style and add it into the style list boxes
rtl::OUString aNewStyle;
- SfxStyleSheetIterator aStyleIter( mpDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
+ SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() )
{
rtl::OUString aName = pStyle->GetName();
- if ( maLbStyle.GetEntryPos(aName) == LISTBOX_ENTRY_NOTFOUND ) // all lists contain the same entries
+ if ( rLbStyle.GetEntryPos(aName) == LISTBOX_ENTRY_NOTFOUND ) // all lists contain the same entries
{
- maLbStyle.InsertEntry(aName);
- maLbStyle.SelectEntry(aName);
+ rLbStyle.InsertEntry(aName);
+ rLbStyle.SelectEntry(aName);
}
}
}
- rtl::OUString aStyleName = maLbStyle.GetSelectEntry();
- SfxStyleSheetBase* pStyleSheet = mpDoc->GetStyleSheetPool()->Find( aStyleName, SFX_STYLE_FAMILY_PARA );
+ rtl::OUString aStyleName = rLbStyle.GetSelectEntry();
+ SfxStyleSheetBase* pStyleSheet = pDoc->GetStyleSheetPool()->Find( aStyleName, SFX_STYLE_FAMILY_PARA );
if(pStyleSheet)
{
const SfxItemSet& rSet = pStyleSheet->GetItemSet();
- maWdPreview.Init( rSet );
+ rWdPreview.Init( rSet );
}
+}
+}
+
+IMPL_LINK_NOARG(ScConditionFrmtEntry, StyleSelectHdl)
+{
+ StyleSelect( maLbStyle, mpDoc, maWdPreview );
return 0;
}
@@ -495,51 +503,7 @@ void ScFormulaFrmtEntry::Init()
IMPL_LINK_NOARG(ScFormulaFrmtEntry, StyleSelectHdl)
{
- if(maLbStyle.GetSelectEntryPos() == 0)
- {
- // call new style dialog
- SfxUInt16Item aFamilyItem( SID_STYLE_FAMILY, SFX_STYLE_FAMILY_PARA );
- SfxStringItem aRefItem( SID_STYLE_REFERENCE, ScGlobal::GetRscString(STR_STYLENAME_STANDARD) );
-
- // unlock the dispatcher so SID_STYLE_NEW can be executed
- // (SetDispatcherLock would affect all Calc documents)
- ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
- SfxDispatcher* pDisp = pViewShell->GetDispatcher();
- sal_Bool bLocked = pDisp->IsLocked();
- if (bLocked)
- pDisp->Lock(false);
-
- // Execute the "new style" slot, complete with undo and all necessary updates.
- // The return value (SfxUInt16Item) is ignored, look for new styles instead.
- pDisp->Execute( SID_STYLE_NEW, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD | SFX_CALLMODE_MODAL,
- &aFamilyItem,
- &aRefItem,
- 0L );
-
- if (bLocked)
- pDisp->Lock(sal_True);
-
- // Find the new style and add it into the style list boxes
- rtl::OUString aNewStyle;
- SfxStyleSheetIterator aStyleIter( mpDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
- for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() )
- {
- rtl::OUString aName = pStyle->GetName();
- if ( maLbStyle.GetEntryPos(aName) == LISTBOX_ENTRY_NOTFOUND ) // all lists contain the same entries
- {
- maLbStyle.InsertEntry(aName);
- maLbStyle.SelectEntry(aName);
- }
- }
- }
-
- rtl::OUString aStyleName = maLbStyle.GetSelectEntry();
- SfxStyleSheetBase* pStyleSheet = mpDoc->GetStyleSheetPool()->Find( aStyleName, SFX_STYLE_FAMILY_PARA );
- if(pStyleSheet)
- {
- const SfxItemSet& rSet = pStyleSheet->GetItemSet();
- maWdPreview.Init( rSet );
- }
+ StyleSelect( maLbStyle, mpDoc, maWdPreview );
return 0;
}
@@ -1169,4 +1133,75 @@ IMPL_LINK_NOARG( ScDataBarFrmtEntry, OptionBtnHdl )
return 0;
}
+ScDateFrmtEntry::ScDateFrmtEntry( Window* pParent, ScDocument* pDoc, const ScCondDateFormatEntry* pFormat ):
+ ScCondFrmtEntry( pParent, pDoc, ScAddress() ),
+ maLbDateEntry( this, ScResId( LB_DATE_TYPE ) ),
+ maFtStyle( this, ScResId( FT_STYLE ) ),
+ maLbStyle( this, ScResId( LB_STYLE ) ),
+ maWdPreview( this, ScResId( WD_PREVIEW ) )
+{
+ Init();
+ FreeResource();
+
+ if(pFormat)
+ {
+ sal_Int32 nPos = static_cast<sal_Int32>(pFormat->GetDateType());
+ maLbDateEntry.SelectEntryPos(nPos);
+ }
+}
+
+void ScDateFrmtEntry::Init()
+{
+ maLbDateEntry.SelectEntryPos(0);
+ maLbType.SelectEntryPos(3);
+
+ maLbStyle.SetSeparatorPos(0);
+ SfxStyleSheetIterator aStyleIter( mpDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
+ for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() )
+ {
+ rtl::OUString aName = pStyle->GetName();
+ maLbStyle.InsertEntry( aName );
+ }
+ maLbStyle.SetSelectHdl( LINK( this, ScDateFrmtEntry, StyleSelectHdl ) );
+}
+
+void ScDateFrmtEntry::SetActive()
+{
+ maLbDateEntry.Show();
+ maFtStyle.Show();
+ maWdPreview.Show();
+
+ Select();
+}
+
+void ScDateFrmtEntry::SetInactive()
+{
+ maLbDateEntry.Show();
+ maFtStyle.Show();
+ maWdPreview.Show();
+
+ Deselect();
+}
+
+ScFormatEntry* ScDateFrmtEntry::GetEntry() const
+{
+ ScCondDateFormatEntry* pNewEntry = new ScCondDateFormatEntry(mpDoc);
+ condformat::ScCondFormatDateType eType = static_cast<condformat::ScCondFormatDateType>(maLbDateEntry.GetSelectEntryPos());
+ pNewEntry->SetDateType(eType);
+ pNewEntry->SetStyleName(maLbStyle.GetSelectEntry());
+ return pNewEntry;
+}
+
+rtl::OUString ScDateFrmtEntry::GetExpressionString()
+{
+ return ScCondFormatHelper::GetExpression(DATE, 0);
+}
+
+IMPL_LINK_NOARG( ScDateFrmtEntry, StyleSelectHdl )
+{
+ StyleSelect( maLbStyle, mpDoc, maWdPreview );
+
+ return 0;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/condformat/condformathelper.cxx b/sc/source/ui/condformat/condformathelper.cxx
index 09eaa24..67a175d 100644
--- a/sc/source/ui/condformat/condformathelper.cxx
+++ b/sc/source/ui/condformat/condformathelper.cxx
@@ -27,6 +27,8 @@ rtl::OUString getTextForType(ScCondFormatEntryType eType)
return ScGlobal::GetRscString(STR_COND_FORMULA);
case ICONSET:
return ScGlobal::GetRscString(STR_COND_ICONSET);
+ case DATE:
+ return ScGlobal::GetRscString(STR_COND_DATE);
default:
break;
}
@@ -136,6 +138,9 @@ rtl::OUString ScCondFormatHelper::GetExpression(const ScConditionalFormat& rForm
case condformat::ICONSET:
aBuffer.append(getTextForType(ICONSET));
break;
+ case condformat::DATE:
+ aBuffer.append(getTextForType(DATE));
+ break;
}
}
return aBuffer.makeStringAndClear();
diff --git a/sc/source/ui/inc/condformatdlg.hrc b/sc/source/ui/inc/condformatdlg.hrc
index f631b53..b1ede3c 100644
--- a/sc/source/ui/inc/condformatdlg.hrc
+++ b/sc/source/ui/inc/condformatdlg.hrc
@@ -67,4 +67,6 @@
#define LB_TYPE_COL_SCALE_MIN 42
#define LB_TYPE_COL_SCALE_MIDDLE 43
#define LB_TYPE_COL_SCALE_MAX 44
+
+#define LB_DATE_TYPE 45
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/condformatdlgentry.hxx b/sc/source/ui/inc/condformatdlgentry.hxx
index 0abe83b..b842ed2 100644
--- a/sc/source/ui/inc/condformatdlgentry.hxx
+++ b/sc/source/ui/inc/condformatdlgentry.hxx
@@ -21,7 +21,8 @@ enum ScCondFrmtEntryType
FORMULA,
COLORSCALE2,
COLORSCALE3,
- DATABAR
+ DATABAR,
+ DATE
};
}
@@ -74,7 +75,6 @@ public:
class ScConditionFrmtEntry : public ScCondFrmtEntry
{
-
//cond format ui elements
ListBox maLbCondType;
formula::RefEdit maEdVal1;
@@ -216,4 +216,27 @@ public:
virtual condformat::entry::ScCondFrmtEntryType GetType() { return condformat::entry::DATABAR; }
};
+class ScDateFrmtEntry : public ScCondFrmtEntry
+{
+public:
+ ScDateFrmtEntry( Window* pParent, ScDocument* pDoc, const ScCondDateFormatEntry* pFormat = NULL );
+ virtual ScFormatEntry* GetEntry() const;
+ virtual void SetActive();
+ virtual void SetInactive();
+ virtual condformat::entry::ScCondFrmtEntryType GetType() { return condformat::entry::DATE; }
+
+protected:
+ virtual rtl::OUString GetExpressionString();
+
+private:
+ void Init();
+
+ DECL_LINK( StyleSelectHdl, void* );
+
+ ListBox maLbDateEntry;
+ FixedText maFtStyle;
+ ListBox maLbStyle;
+ SvxFontPrevWindow maWdPreview;
+};
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/condformathelper.hxx b/sc/source/ui/inc/condformathelper.hxx
index c674df4..02d24e6 100644
--- a/sc/source/ui/inc/condformathelper.hxx
+++ b/sc/source/ui/inc/condformathelper.hxx
@@ -19,7 +19,8 @@ enum ScCondFormatEntryType
DATABAR,
FORMULA,
ICONSET,
- COLLAPSED
+ DATE,
+ COLLAPSE
};
class ScCondFormatHelper
diff --git a/sc/source/ui/src/condformatdlg.src b/sc/source/ui/src/condformatdlg.src
index 8318cc1..ab98866 100644
--- a/sc/source/ui/src/condformatdlg.src
+++ b/sc/source/ui/src/condformatdlg.src
@@ -121,6 +121,7 @@ Control RID_COND_ENTRY
"All Cells";
"Cell value is";
"Formula is";
+ "Date is";
};
};
ListBox LB_CELLIS_TYPE
@@ -309,6 +310,30 @@ Control RID_COND_ENTRY
Size = MAP_APPFONT( 60, 14 );
Text [ en-US ] = "More options ...";
};
+ ListBox LB_DATE_TYPE
+ {
+ Pos = MAP_APPFONT( 100, 15 );
+ Size = MAP_APPFONT( 100, 60 );
+ Border = TRUE;
+ DropDown = TRUE;
+ DDExtraWidth = TRUE;
+ StringList [ en-US ] =
+ {
+ "Today";
+ "Yesterday";
+ "Tomorrow";
+ "Last 7 days";
+ "This week";
+ "Last week";
+ "Next week";
+ "This month";
+ "Last month";
+ "Next month";
+ "This year";
+ "Last year";
+ "Next year";
+ };
+ };
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src
index 226bb1a..49e9176 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -1911,6 +1911,10 @@ Resource RID_GLOBSTR
{
Text [ en-US ] = "Top Percent";
};
+ String STR_COND_DATE
+ {
+ Text [ en-US ] = "Date is";
+ };
String STR_COND_BOTTOM_PERCENT
{
Text [ en-US ] = "Bottom Percent";
commit ee1af6790434bd9364334ffe14cdba21979b6381
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Thu Nov 15 23:37:18 2012 +0100
implement remaining conditional date formats
Change-Id: I0a514f305367f556be2fea6650afb63bff4c5a8c
diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index cdc02f5..71dcc4e 100644
--- a/sc/inc/conditio.hxx
+++ b/sc/inc/conditio.hxx
@@ -329,16 +329,19 @@ namespace condformat {
enum ScCondFormatDateType
{
+ TODAY,
YESTERDAY,
TOMORROW,
- TODAY,
LAST7DAYS,
- LASTWEEK,
THISWEEK,
+ LASTWEEK,
NEXTWEEK,
- LASTMONTH,
THISMONTH,
- NEXTMONTH
+ LASTMONTH,
+ NEXTMONTH,
+ THISYEAR,
+ LASTYEAR,
+ NEXTYEAR
};
}
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index d0d388b..769a95e 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -1650,12 +1650,15 @@ bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const
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());
+ double nVal = mpDoc->GetValue(rPos);
+ long nCellDate = static_cast<long>(nVal);
+ Date aCellDate = *(pFormatter->GetNullDate());
+ aCellDate += (long) ::rtl::math::approxFloor(nVal);
+
switch(meType)
{
case condformat::TODAY:
@@ -1670,8 +1673,63 @@ bool ScCondDateFormatEntry::IsValid( const ScAddress& rPos ) const
if( nCurrentDate == nCellDate + 1)
return true;
break;
- default:
- return true;
+ case condformat::LAST7DAYS:
+ if( nCurrentDate >= nCellDate && nCurrentDate - 7 < nCellDate )
+ return true;
+ break;
+ case condformat::LASTWEEK:
+ if( aActDate.GetYear() == aCellDate.GetYear() && aActDate.GetMonth() == aCellDate.GetMonth() )
+ {
+ if( aActDate.GetWeekOfYear( SUNDAY ) == aCellDate.GetWeekOfYear( SUNDAY ) + 1 )
+ return true;
+ }
+ break;
+ case condformat::THISWEEK:
+ if( aActDate.GetYear() == aCellDate.GetYear() && aActDate.GetMonth() == aCellDate.GetMonth() )
+ {
+ if( aActDate.GetWeekOfYear( SUNDAY ) == aCellDate.GetWeekOfYear( SUNDAY ) )
+ return true;
+ }
+ break;
+ case condformat::NEXTWEEK:
+ if( aActDate.GetYear() == aCellDate.GetYear() && aActDate.GetMonth() == aCellDate.GetMonth() )
+ {
+ if( aActDate.GetWeekOfYear( SUNDAY ) == aCellDate.GetWeekOfYear( SUNDAY ) - 1 )
+ return true;
+ }
+ break;
+ case condformat::LASTMONTH:
+ if( aActDate.GetYear() == aCellDate.GetYear() )
+ {
+ if( aActDate.GetMonth() == aCellDate.GetMonth() + 1)
+ return true;
+ }
+ break;
+ case condformat::THISMONTH:
+ if( aActDate.GetYear() == aCellDate.GetYear() )
+ {
+ if( aActDate.GetMonth() == aCellDate.GetMonth() )
+ return true;
+ }
+ break;
+ case condformat::NEXTMONTH:
+ if( aActDate.GetYear() == aCellDate.GetYear() )
+ {
+ if( aActDate.GetMonth() == aCellDate.GetMonth() - 1)
+ return true;
+ }
+ break;
+ case condformat::LASTYEAR:
+ if( aActDate.GetYear() == aCellDate.GetYear() + 1 )
+ return true;
+ break;
+ case condformat::THISYEAR:
+ if( aActDate.GetYear() == aCellDate.GetYear() )
+ return true;
+ break;
+ case condformat::NEXTYEAR:
+ if( aActDate.GetYear() == aCellDate.GetYear() - 1 )
+ return true;
break;
}
commit f3ddf0922ba08e3237379151f169c7e508914a39
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Thu Nov 15 13:11:19 2012 +0100
implement date cond format import from OOXML
Change-Id: I4c0fc2dad8510260ee58848f99736c91ae58c57e
diff --git a/sc/source/filter/oox/condformatbuffer.cxx b/sc/source/filter/oox/condformatbuffer.cxx
index 7840be1..1b66341 100644
--- a/sc/source/filter/oox/condformatbuffer.cxx
+++ b/sc/source/filter/oox/condformatbuffer.cxx
@@ -692,41 +692,6 @@ void CondFormatRule::finalizeImport()
eOperator = SC_COND_ENDS_WITH;
break;
case XML_timePeriod:
- switch( maModel.mnTimePeriod )
- {
- case XML_yesterday:
- aReplaceFormula = "FLOOR(#B,1)=TODAY()-1";
- break;
- case XML_today:
- aReplaceFormula = "FLOOR(#B,1)=TODAY()";
- break;
- case XML_tomorrow:
- aReplaceFormula = "FLOOR(#B,1)=TODAY()+1";
- break;
- case XML_last7Days:
- aReplaceFormula = "AND(TODAY()-7<FLOOR(#B,1),FLOOR(#B,1)<=TODAY())";
- break;
- case XML_lastWeek:
- aReplaceFormula = "AND(TODAY()-WEEKDAY(TODAY())-7<FLOOR(#B,1),FLOOR(#B,1)<=TODAY()-WEEKDAY(TODAY()))";
- break;
- case XML_thisWeek:
- aReplaceFormula = "AND(TODAY()-WEEKDAY(TODAY())<FLOOR(#B,1),FLOOR(#B,1)<=TODAY()-WEEKDAY(TODAY())+7)";
- break;
- case XML_nextWeek:
- aReplaceFormula = "AND(TODAY()-WEEKDAY(TODAY())+7<FLOOR(#B,1),FLOOR(#B,1)<=TODAY()-WEEKDAY(TODAY())+14)";
- break;
- case XML_lastMonth:
- aReplaceFormula = "OR(AND(MONTH(#B)=MONTH(TODAY())-1,YEAR(#B)=YEAR(TODAY())),AND(MONTH(#B)=12,MONTH(TODAY())=1,YEAR(#B)=YEAR(TODAY())-1))";
- break;
- case XML_thisMonth:
- aReplaceFormula = "AND(MONTH(#B)=MONTH(TODAY()),YEAR(#B)=YEAR(TODAY()))";
- break;
- case XML_nextMonth:
- aReplaceFormula = "OR(AND(MONTH(#B)=MONTH(TODAY())+1,YEAR(#B)=YEAR(TODAY())),AND(MONTH(#B)=1,MONTH(TODAY())=12,YEAR(#B)=YEAR(TODAY())+1))";
- break;
- default:
- OSL_FAIL( "CondFormatRule::finalizeImport - unknown time period type" );
- }
break;
case XML_containsBlanks:
aReplaceFormula = "LEN(TRIM(#B))=0";
@@ -856,6 +821,53 @@ void CondFormatRule::finalizeImport()
ScCondFormatEntry* pNewEntry = new ScCondFormatEntry( eOperator, NULL, NULL, &rDoc, aPos, aStyleName );
mpFormat->AddEntry(pNewEntry);
}
+ else if( maModel.mnType == XML_timePeriod )
+ {
+ condformat::ScCondFormatDateType eDateType = condformat::TODAY;
+ switch( maModel.mnTimePeriod )
+ {
+ case XML_yesterday:
+ eDateType = condformat::YESTERDAY;
+ break;
+ case XML_today:
+ eDateType = condformat::TODAY;
+ break;
+ case XML_tomorrow:
+ eDateType = condformat::TOMORROW;
+ break;
+ case XML_last7Days:
+ eDateType = condformat::LAST7DAYS;
+ break;
+ case XML_lastWeek:
+ eDateType = condformat::LASTWEEK;
+ break;
+ case XML_thisWeek:
+ eDateType = condformat::THISWEEK;
+ break;
+ case XML_nextWeek:
+ eDateType = condformat::NEXTWEEK;
+ break;
+ case XML_lastMonth:
+ eDateType = condformat::LASTMONTH;
+ break;
+ case XML_thisMonth:
+ eDateType = condformat::THISMONTH;
+ break;
+ case XML_nextMonth:
+ eDateType = condformat::NEXTMONTH;
+ break;
+ default:
+ SAL_WARN("sc", "CondFormatRule::finalizeImport - unknown time period type" );
+ }
+
+ ScDocument& rDoc = getScDocument();
+ ScCondDateFormatEntry* pFormatEntry = new ScCondDateFormatEntry(&rDoc);
+ pFormatEntry->SetDateType(eDateType);
+ OUString aStyleName = getStyles().createDxfStyle( maModel.mnDxfId );
+ pFormatEntry->SetStyleName( aStyleName );
+
+ mpFormat->AddEntry(pFormatEntry);
+ }
else if( mpColor )
{
ScDocument& rDoc = getScDocument();
commit 95634322a93dfab4378206d4269f3d5cbcdaedc1
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Thu Nov 15 13:10:56 2012 +0100
initial work for date conditional formats
Change-Id: Ifba8a4061e898a031004c20222e78eb825f07e4e
diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index 1009df7..cdc02f5 100644
--- a/sc/inc/conditio.hxx
+++ b/sc/inc/conditio.hxx
@@ -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
//
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 12fe329..d0d388b 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -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;
}
commit ced69036671bd995b5af0e521cf913a0fb11753d
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Thu Nov 15 13:10:28 2012 +0100
String to OUString
Change-Id: I32f35a34f031b1905b1b3955d6a8e6804bd4ce23
diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index bf4ca53..1009df7 100644
--- a/sc/inc/conditio.hxx
+++ b/sc/inc/conditio.hxx
@@ -293,7 +293,7 @@ private:
class SC_DLLPUBLIC ScCondFormatEntry : public ScConditionEntry
{
- String aStyleName;
+ rtl::OUString aStyleName;
using ScConditionEntry::operator==;
@@ -316,8 +316,8 @@ public:
int operator== ( const ScCondFormatEntry& r ) const;
- const String& GetStyle() const { return aStyleName; }
- void UpdateStyleName(const String& rNew) { aStyleName=rNew; }
+ const rtl::OUString& GetStyle() const { return aStyleName; }
+ void UpdateStyleName(const rtl::OUString& rNew) { aStyleName=rNew; }
virtual ScFormatEntry* Clone(ScDocument* pDoc) const;
protected:
@@ -360,13 +360,13 @@ public:
const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
void DeleteArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
- void RenameCellStyle( const String& rOld, const String& rNew );
+ void RenameCellStyle( const rtl::OUString& rOld, const rtl::OUString& rNew );
void SourceChanged( const ScAddress& rAddr );
const ScFormatEntry* GetEntry( sal_uInt16 nPos ) const;
- const String& GetCellStyle( ScBaseCell* pCell, const ScAddress& rPos ) const;
+ const rtl::OUString& GetCellStyle( ScBaseCell* pCell, const ScAddress& rPos ) const;
ScCondFormatData GetData( ScBaseCell* pCell, const ScAddress& rPos ) const;
@@ -422,7 +422,7 @@ public:
void CompileXML();
void UpdateReference( UpdateRefMode eUpdateRefMode,
const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
- void RenameCellStyle( const String& rOld, const String& rNew );
+ void RenameCellStyle( const rtl::OUString& rOld, const rtl::OUString& rNew );
void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
void DeleteArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index ecece73..12fe329 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -1707,7 +1707,7 @@ const ScFormatEntry* ScConditionalFormat::GetEntry( sal_uInt16 nPos ) const
return NULL;
}
-const String& ScConditionalFormat::GetCellStyle( ScBaseCell* pCell, const ScAddress& rPos ) const
+const rtl::OUString& ScConditionalFormat::GetCellStyle( ScBaseCell* pCell, const ScAddress& rPos ) const
{
for (CondFormatContainer::const_iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
{
@@ -1719,7 +1719,7 @@ const String& ScConditionalFormat::GetCellStyle( ScBaseCell* pCell, const ScAddr
}
}
- return EMPTY_STRING;
+ return EMPTY_OUSTRING;
}
ScCondFormatData ScConditionalFormat::GetData( ScBaseCell* pCell, const ScAddress& rPos ) const
@@ -1804,7 +1804,7 @@ void ScConditionalFormat::DeleteArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCR
maRanges.DeleteArea( nCol1, nRow1, nTab, nCol2, nRow2, nTab );
}
-void ScConditionalFormat::RenameCellStyle(const String& rOld, const String& rNew)
+void ScConditionalFormat::RenameCellStyle(const rtl::OUString& rOld, const rtl::OUString& rNew)
{
for(CondFormatContainer::iterator itr = maEntries.begin(); itr != maEntries.end(); ++itr)
if(itr->GetType() == condformat::CONDITION)
@@ -1963,7 +1963,7 @@ void ScConditionalFormatList::UpdateReference( UpdateRefMode eUpdateRefMode,
}
}
-void ScConditionalFormatList::RenameCellStyle( const String& rOld, const String& rNew )
+void ScConditionalFormatList::RenameCellStyle( const rtl::OUString& rOld, const rtl::OUString& rNew )
{
for( iterator itr = begin(); itr != end(); ++itr)
itr->RenameCellStyle(rOld,rNew);
commit ca97c8679bc3646160649a5a2f28878a971512f8
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Thu Nov 15 13:07:32 2012 +0100
remove strange comments
Change-Id: I307ac354550119f87e7eee0d747b36715c9e0ccc
diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index d60da24..bf4ca53 100644
--- a/sc/inc/conditio.hxx
+++ b/sc/inc/conditio.hxx
@@ -57,12 +57,12 @@ class ScTokenArray;
enum ScConditionMode
{
- SC_COND_EQUAL, //done
- SC_COND_LESS, //done
+ SC_COND_EQUAL,
+ SC_COND_LESS,
SC_COND_GREATER,
SC_COND_EQLESS,
SC_COND_EQGREATER,
- SC_COND_NOTEQUAL, //done
+ SC_COND_NOTEQUAL,
SC_COND_BETWEEN,
SC_COND_NOTBETWEEN,
SC_COND_DUPLICATE,
More information about the Libreoffice-commits
mailing list