summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-06-10 01:59:23 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-06-11 08:01:26 +0200
commitecc2805d642d2ec562d8ba15a799fcf7d6fae0d8 (patch)
treef265fce9608c7684c17153ff743c0a9574f765d5 /sc
parentc161e8a5a816f649e21105b09723f620336507ac (diff)
correctly set new conditional format
# Change-Id: I6dc3f1cd99cd15aa3dad72a1417f3e2c1af0108d
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/conditio.hxx2
-rw-r--r--sc/inc/document.hxx1
-rw-r--r--sc/inc/table.hxx2
-rw-r--r--sc/source/core/data/attarray.cxx25
-rw-r--r--sc/source/core/data/conditio.cxx12
-rw-r--r--sc/source/core/data/documen4.cxx8
-rw-r--r--sc/source/core/data/table1.cxx5
-rw-r--r--sc/source/ui/condformat/condformatdlg.cxx89
-rw-r--r--sc/source/ui/docshell/docfunc.cxx20
-rw-r--r--sc/source/ui/inc/condformatdlg.hxx1
-rw-r--r--sc/source/ui/inc/docfunc.hxx7
-rw-r--r--sc/source/ui/view/cellsh1.cxx15
12 files changed, 142 insertions, 45 deletions
diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index 73e6ece6eda1..e8b3b3677b3b 100644
--- a/sc/inc/conditio.hxx
+++ b/sc/inc/conditio.hxx
@@ -349,6 +349,8 @@ public:
SC_DLLPUBLIC const_iterator end() const;
size_t size() const;
+
+ void erase(sal_uLong nIndex);
};
#endif
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index cc2780f694aa..61ab60eb7396 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1196,6 +1196,7 @@ public:
void ChangeSelectionIndent( bool bIncrement, const ScMarkData& rMark );
SC_DLLPUBLIC sal_uLong AddCondFormat( ScConditionalFormat* pNew, SCTAB nTab );
+ void DeleteConditionalFormat( sal_uLong nIndex, SCTAB nTab );
SC_DLLPUBLIC void FindConditionalFormat( sal_uLong nKey, SCTAB nTab, ScRangeList& rRanges );
SC_DLLPUBLIC void FindConditionalFormat( sal_uLong nKey, ScRangeList& rRanges, SCTAB nTab );
void ConditionalChanged( sal_uLong nKey, SCTAB nTab );
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 4c5d69759eed..7756f770cedd 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -797,6 +797,8 @@ public:
ScConditionalFormatList* GetCondFormList();
const ScConditionalFormatList* GetCondFormList() const;
+ void DeleteConditionalFormat(sal_uLong nOldIndex);
+
sal_uLong AddCondFormat( ScConditionalFormat* pNew );
private:
diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx
index 08ef1dbffafc..3c333f940721 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -144,14 +144,6 @@ void ScAttrArray::Reset( const ScPatternAttr* pPattern, bool bAlloc )
aAdrEnd .SetRow( pData[i].nRow );
pDocument->InvalidateTextWidth( &aAdrStart, &aAdrEnd, bNumFormatChanged );
}
- // conditional format or deleted?
- if ( &pPattern->GetItem(ATTR_CONDITIONAL) != &pOldPattern->GetItem(ATTR_CONDITIONAL) )
- {
- pDocument->ConditionalChanged( ((const SfxUInt32Item&)
- pOldPattern->GetItem(ATTR_CONDITIONAL)).GetValue(), nTab );
- pDocument->ConditionalChanged( ((const SfxUInt32Item&)
- pPattern->GetItem(ATTR_CONDITIONAL)).GetValue(), nTab );
- }
pDocPool->Remove(*pOldPattern);
}
delete[] pData;
@@ -370,13 +362,6 @@ void ScAttrArray::SetPatternArea(SCROW nStartRow, SCROW nEndRow, const ScPattern
aAdrEnd .SetRow( Min(nEndRow,pData[nx].nRow) );
pDocument->InvalidateTextWidth( &aAdrStart, &aAdrEnd, bNumFormatChanged );
}
- if ( &rNewSet.Get(ATTR_CONDITIONAL) != &rOldSet.Get(ATTR_CONDITIONAL) )
- {
- pDocument->ConditionalChanged( ((const SfxUInt32Item&)
- rOldSet.Get(ATTR_CONDITIONAL)).GetValue(), nTab );
- pDocument->ConditionalChanged( ((const SfxUInt32Item&)
- rNewSet.Get(ATTR_CONDITIONAL)).GetValue(), nTab );
- }
ns = pData[nx].nRow + 1;
nx++;
}
@@ -773,16 +758,6 @@ void ScAttrArray::ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, SfxItemPoolCac
pDocument->InvalidateTextWidth( &aAdrStart, &aAdrEnd, bNumFormatChanged );
}
- // Reset conditional formats or delete ?
-
- if ( &rNewSet.Get(ATTR_CONDITIONAL) != &rOldSet.Get(ATTR_CONDITIONAL) )
- {
- pDocument->ConditionalChanged( ((const SfxUInt32Item&)
- rOldSet.Get(ATTR_CONDITIONAL)).GetValue(), nTab );
- pDocument->ConditionalChanged( ((const SfxUInt32Item&)
- rNewSet.Get(ATTR_CONDITIONAL)).GetValue(), nTab );
- }
-
pDocument->GetPool()->Remove(*pData[nPos].pPattern);
pData[nPos].pPattern = pNewPattern;
if (Concat(nPos))
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 77b1540ca499..f4d137bcfd2a 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -1762,4 +1762,16 @@ size_t ScConditionalFormatList::size() const
return maConditionalFormats.size();
}
+void ScConditionalFormatList::erase( sal_uLong nIndex )
+{
+ for( iterator itr = begin(); itr != end(); ++itr )
+ {
+ if( itr->GetKey() == nIndex )
+ {
+ maConditionalFormats.erase(itr);
+ break;
+ }
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 52b9f8b29124..f6bb911e95e4 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -733,12 +733,10 @@ void ScDocument::FindConditionalFormat( sal_uLong nKey, ScRangeList& rRanges, SC
maTabs[nTab]->FindConditionalFormat( nKey, rRanges );
}
-void ScDocument::ConditionalChanged( sal_uLong nKey, SCTAB nTab )
+void ScDocument::DeleteConditionalFormat(sal_uLong nOldIndex, SCTAB nTab)
{
- ScConditionalFormatList* pCondFormList = GetCondFormList(nTab);
- if ( nKey && pCondFormList && !bIsClip && !bIsUndo ) // nKey==0 -> noop
- {
- }
+ if(VALIDTAB(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
+ maTabs[nTab]->DeleteConditionalFormat(nOldIndex);
}
//------------------------------------------------------------------------
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index b1acdf6d7622..bdf78328edbd 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -2016,6 +2016,11 @@ sal_uLong ScTable::AddCondFormat( ScConditionalFormat* pNew )
return nMax + 1;
}
+void ScTable::DeleteConditionalFormat( sal_uLong nIndex )
+{
+ mpCondFormatList->erase(nIndex);
+}
+
void ScTable::SetCondFormList( ScConditionalFormatList* pNew )
{
mpCondFormatList.reset( pNew );
diff --git a/sc/source/ui/condformat/condformatdlg.cxx b/sc/source/ui/condformat/condformatdlg.cxx
index 6f13586a9944..0f27399959da 100644
--- a/sc/source/ui/condformat/condformatdlg.cxx
+++ b/sc/source/ui/condformat/condformatdlg.cxx
@@ -84,6 +84,34 @@ void SetColorScaleEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType,
rLbCol.SelectEntry(rEntry.GetColor());
}
+void SetDataBarEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Edit& rEdit )
+{
+ if(rEntry.GetMin())
+ rLbType.SelectEntryPos(0);
+ else if(rEntry.GetMax())
+ rLbType.SelectEntryPos(1);
+ else if(rEntry.GetPercentile())
+ {
+ rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
+ rLbType.SelectEntryPos(2);
+ }
+ else if(rEntry.GetPercent())
+ {
+ rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
+ rLbType.SelectEntryPos(4);
+ }
+ else if(rEntry.HasFormula())
+ {
+ rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
+ rLbType.SelectEntryPos(5);
+ }
+ else
+ {
+ rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
+ rLbType.SelectEntryPos(3);
+ }
+}
+
}
ScCondFrmtEntry::ScCondFrmtEntry(Window* pParent, ScDocument* pDoc):
@@ -132,6 +160,11 @@ ScCondFrmtEntry::ScCondFrmtEntry(Window* pParent, ScDocument* pDoc):
maLbEntryTypeMin.SelectEntryPos(0);
maLbEntryTypeMiddle.SelectEntryPos(2);
maLbEntryTypeMax.SelectEntryPos(1);
+ maLbDataBarMinType.SelectEntryPos(0);
+ maLbDataBarMaxType.SelectEntryPos(1);
+ maEdMiddle.SetText(rtl::OUString::valueOf(50));
+ maEdDataBarMin.Disable();
+ maEdDataBarMax.Disable();
Init();
maLbStyle.SelectEntryPos(1);
@@ -250,6 +283,9 @@ ScCondFrmtEntry::ScCondFrmtEntry(Window* pParent, ScDocument* pDoc, const ScForm
mpDataBarData.reset(new ScDataBarFormatData(*pEntry->GetDataBarData()));
maLbType.SelectEntryPos(0);
maLbColorFormat.SelectEntryPos(2);
+ SetDataBarEntryTypes(*mpDataBarData->mpLowerLimit, maLbDataBarMinType, maEdDataBarMin);
+ SetDataBarEntryTypes(*mpDataBarData->mpUpperLimit, maLbDataBarMaxType, maEdDataBarMax);
+ DataBarTypeSelectHdl(NULL);
SetDataBarType();
}
@@ -288,7 +324,7 @@ void ScCondFrmtEntry::Init()
maLbEntryTypeMiddle.SetPosPixel(aPointLb);
maEdMiddle.SetPosPixel(aPointEd);
maLbColMiddle.SetPosPixel(aPointCol);
- maEdDataBarMin.SetPosPixel(aPointEdDataBar);
+ maEdDataBarMax.SetPosPixel(aPointEdDataBar);
maLbDataBarMaxType.SetPosPixel(aPointLbDataBar);
aPointLb.X() += nMovePos;
aPointEd.X() += nMovePos;
@@ -336,12 +372,15 @@ void ScCondFrmtEntry::Init()
}
maBtOptions.SetClickHdl( LINK( this, ScCondFrmtEntry, OptionBtnHdl ) );
+ maLbDataBarMinType.SetSelectHdl( LINK( this, ScCondFrmtEntry, DataBarTypeSelectHdl ) );
+ maLbDataBarMaxType.SetSelectHdl( LINK( this, ScCondFrmtEntry, DataBarTypeSelectHdl ) );
mpDataBarData.reset(new ScDataBarFormatData());
mpDataBarData->mpUpperLimit.reset(new ScColorScaleEntry());
mpDataBarData->mpLowerLimit.reset(new ScColorScaleEntry());
mpDataBarData->mpLowerLimit->SetMin(true);
mpDataBarData->mpUpperLimit->SetMax(true);
+ mpDataBarData->maPositiveColor = COL_LIGHTBLUE;
}
namespace {
@@ -373,10 +412,20 @@ rtl::OUString getExpression(sal_Int32 nIndex)
return rtl::OUString("<");
case 2:
return rtl::OUString(">");
+ case 3:
+ return rtl::OUString("<=");
+ case 4:
+ return rtl::OUString(">=");
case 5:
return rtl::OUString("!=");
- default:
- return rtl::OUString("not yet supported");
+ case 6:
+ return rtl::OUString("between");
+ case 7:
+ return rtl::OUString("not between");
+ case 8:
+ return rtl::OUString("duplicate");
+ case 9:
+ return rtl::OUString("unique");
}
return rtl::OUString();
}
@@ -401,7 +450,8 @@ void ScCondFrmtEntry::SwitchToType( ScCondFormatEntryType eType )
maLbType.Hide();
rtl::OUStringBuffer maCondText(getTextForType(meType));
maCondText.append(rtl::OUString(" "));
- maCondText.append(getExpression(maLbCondType.GetSelectEntryPos()));
+ if(meType == CONDITION)
+ maCondText.append(getExpression(maLbCondType.GetSelectEntryPos()));
maFtCondition.SetText(maCondText.makeStringAndClear());
maFtCondition.Show();
}
@@ -612,9 +662,8 @@ ScFormatEntry* ScCondFrmtEntry::createConditionEntry() const
namespace {
-ScColorScaleEntry* createColorScaleEntry( const ListBox& rType, const ColorListBox& rColor, const Edit& rValue, ScDocument* pDoc, const ScAddress& rPos )
+void SetColorScaleEntry( ScColorScaleEntry* pEntry, const ListBox& rType, const Edit& rValue, ScDocument* pDoc, const ScAddress& rPos )
{
- ScColorScaleEntry* pEntry = new ScColorScaleEntry();
double nVal = rtl::math::stringToDouble(rValue.GetText(), '.', ',');
switch(rType.GetSelectEntryPos())
{
@@ -639,7 +688,13 @@ ScColorScaleEntry* createColorScaleEntry( const ListBox& rType, const ColorListB
pEntry->SetFormula(rValue.GetText(), pDoc, rPos);
break;
}
+}
+ScColorScaleEntry* createColorScaleEntry( const ListBox& rType, const ColorListBox& rColor, const Edit& rValue, ScDocument* pDoc, const ScAddress& rPos )
+{
+ ScColorScaleEntry* pEntry = new ScColorScaleEntry();
+
+ SetColorScaleEntry( pEntry, rType, rValue, pDoc, rPos );
Color aColor = rColor.GetSelectEntryColor();
pEntry->SetColor(aColor);
return pEntry;
@@ -774,13 +829,33 @@ IMPL_LINK_NOARG(ScCondFrmtEntry, StyleSelectHdl)
return 0;
}
+IMPL_LINK_NOARG( ScCondFrmtEntry, DataBarTypeSelectHdl )
+{
+ sal_Int32 nSelectPos = maLbDataBarMinType.GetSelectEntryPos();
+ if(nSelectPos == 0 || nSelectPos == 1)
+ maEdDataBarMin.Disable();
+ else
+ maEdDataBarMin.Enable();
+
+ nSelectPos = maLbDataBarMaxType.GetSelectEntryPos();
+ if(nSelectPos == 0 || nSelectPos == 1)
+ maEdDataBarMax.Disable();
+ else
+ maEdDataBarMax.Enable();
+
+ return 0;
+}
+
IMPL_LINK_NOARG( ScCondFrmtEntry, OptionBtnHdl )
{
+ SetColorScaleEntry(mpDataBarData->mpLowerLimit.get(), maLbDataBarMinType, maEdDataBarMin, mpDoc, maPos);
+ SetColorScaleEntry(mpDataBarData->mpUpperLimit.get(), maLbDataBarMaxType, maEdDataBarMax, mpDoc, maPos);
ScDataBarSettingsDlg* pDlg = new ScDataBarSettingsDlg(this, *mpDataBarData);
if( pDlg->Execute() == RET_OK)
{
- std::cout << "Ok" << std::endl;
mpDataBarData.reset(pDlg->GetData());
+ SetDataBarEntryTypes(*mpDataBarData->mpLowerLimit, maLbDataBarMinType, maEdDataBarMin);
+ SetDataBarEntryTypes(*mpDataBarData->mpUpperLimit, maLbDataBarMaxType, maEdDataBarMax);
}
return 0;
}
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index ffd5e1a3a270..191dd7834714 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -5058,7 +5058,27 @@ sal_Bool ScDocFunc::InsertAreaLink( const String& rFile, const String& rFilter,
return sal_True;
}
+void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, ScConditionalFormat* pFormat, SCTAB nTab, const ScRangeList& rRanges )
+{
+ ScDocShellModificator aModificator(rDocShell);
+ ScDocument* pDoc = rDocShell.GetDocument();
+ if(nOldFormat)
+ {
+ pDoc->DeleteConditionalFormat(nOldFormat, nTab);
+ }
+ if(pFormat)
+ {
+ sal_uLong nIndex = pDoc->AddCondFormat(pFormat, nTab);
+ ScPatternAttr aPattern( pDoc->GetPool() );
+ aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_CONDITIONAL, nIndex ) );
+ ScMarkData aMarkData;
+ aMarkData.MarkFromRangeList(rRanges, true);
+ pDoc->ApplySelectionPattern( aPattern , aMarkData );
+ }
+ aModificator.SetDocumentModified();
+ SFX_APP()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED));
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/condformatdlg.hxx b/sc/source/ui/inc/condformatdlg.hxx
index d1f80a925e7c..70fef9691062 100644
--- a/sc/source/ui/inc/condformatdlg.hxx
+++ b/sc/source/ui/inc/condformatdlg.hxx
@@ -125,6 +125,7 @@ private:
DECL_LINK( ColFormatTypeHdl, void*);
DECL_LINK( StyleSelectHdl, void* );
DECL_LINK( OptionBtnHdl, void* );
+ DECL_LINK( DataBarTypeSelectHdl, void* );
public:
ScCondFrmtEntry( Window* pParent, ScDocument* pDoc );
diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx
index 9ea375a869eb..f8b6b9b698db 100644
--- a/sc/source/ui/inc/docfunc.hxx
+++ b/sc/source/ui/inc/docfunc.hxx
@@ -52,6 +52,7 @@ class ScTokenArray;
struct ScTabOpParam;
class ScTableProtection;
struct ScCellMergeOption;
+class ScConditionalFormat;
// ---------------------------------------------------------------------------
@@ -202,6 +203,12 @@ public:
const String& rOptions, const String& rSource,
const ScRange& rDestRange, sal_uLong nRefresh,
sal_Bool bFitBlock, sal_Bool bApi );
+
+ /**
+ * @param nOldIndex If 0 don't delete an old format
+ * @param pFormat if NULL only delete an old format
+ */
+ virtual void ReplaceConditionalFormat( sal_uLong nOldIndex, ScConditionalFormat* pFormat, SCTAB nTab, const ScRangeList& rRanges );
};
class ScDocFuncDirect : public ScDocFunc
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index d9c78cd69038..c0a59a95c4d8 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -2056,11 +2056,11 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
ScRangeList aRangeList;
- ScViewData* pViewData = GetViewData();
- pViewData->GetMarkData().FillRangeListWithMarks(&aRangeList, false);
+ ScViewData* pData = GetViewData();
+ pData->GetMarkData().FillRangeListWithMarks(&aRangeList, false);
ScDocument* pDoc = GetViewData()->GetDocument();
- ScAddress aPos(pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo());
+ ScAddress aPos(pData->GetCurX(), pData->GetCurY(), pData->GetTabNo());
AbstractScCondFormatDlg* pDlg = NULL;
const ScConditionalFormat* pCondFormat = pDoc->GetCondFormat(aPos.Col(), aPos.Row(), aPos.Tab());
if(pCondFormat)
@@ -2075,11 +2075,10 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
if(pDlg->Execute() == RET_OK)
{
ScConditionalFormat* pFormat = pDlg->GetConditionalFormat();
- sal_uLong nIndex = pDoc->AddCondFormat(pFormat, pViewData->GetTabNo());
-
- ScPatternAttr aPattern( pDoc->GetPool() );
- aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_CONDITIONAL, nIndex ) );
- pDoc->ApplySelectionPattern( aPattern , pViewData->GetMarkData() );
+ sal_uLong nOldIndex = 0;
+ if(pCondFormat)
+ nOldIndex = pCondFormat->GetKey();
+ pData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat( nOldIndex, pFormat, pData->GetTabNo(), pFormat->GetRange() );
}
delete pDlg;
}