summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2010-09-15 17:11:24 +0200
committerFridrich Štrba <fridrich.strba@bluewin.ch>2010-09-15 17:11:24 +0200
commit0701397a485c6cce318fbf8751bf8894dca314c4 (patch)
tree699577c0bad8828cb5c45f901374fe6bcb6bcb76
parent5e3d27c198bf6dd05641e6473766c7062c248244 (diff)
sc-cellformat-icon-toggle.diff: Cell number format toolbar icons togglable
n#358548, i#86377 Make cell number format toolbar icons togglable & remove the standard format button.
-rw-r--r--sc/inc/column.hxx1
-rw-r--r--sc/inc/document.hxx1
-rw-r--r--sc/inc/table.hxx1
-rw-r--r--sc/sdi/formatsh.sdi10
-rw-r--r--sc/source/core/data/column.cxx16
-rw-r--r--sc/source/core/data/document.cxx26
-rw-r--r--sc/source/core/data/table2.cxx8
-rw-r--r--sc/source/ui/inc/formatsh.hxx3
-rw-r--r--sc/source/ui/view/formatsh.cxx124
-rw-r--r--sc/source/ui/view/tabview3.cxx7
-rw-r--r--sc/uiconfig/scalc/toolbar/formatobjectbar.xml2
11 files changed, 184 insertions, 15 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 1a021dcb0cce..2fa63eb91d74 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -301,6 +301,7 @@ public:
const ScPatternAttr* GetMostUsedPattern( SCROW nStartRow, SCROW nEndRow ) const;
ULONG GetNumberFormat( SCROW nRow ) const;
+ sal_uInt32 GetNumberFormat( SCROW nStartRow, SCROW nEndRow ) const;
void MergeSelectionPattern( ScMergePatternState& rState, const ScMarkData& rMark, BOOL bDeep ) const;
void MergePatternArea( ScMergePatternState& rState, SCROW nRow1, SCROW nRow2, BOOL bDeep ) const;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index e8d84880f0ad..cecf424501cf 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -794,6 +794,7 @@ public:
SC_DLLPUBLIC double RoundValueAsShown( double fVal, ULONG nFormat );
SC_DLLPUBLIC void GetNumberFormat( SCCOL nCol, SCROW nRow, SCTAB nTab,
sal_uInt32& rFormat );
+ sal_uInt32 GetNumberFormat( const ScRange& rRange ) const;
SC_DLLPUBLIC sal_uInt32 GetNumberFormat( const ScAddress& ) const;
/** If no number format attribute is set and the cell
pointer passed is of type formula cell, the calculated
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index aacce96bc711..18aa7ce82fd5 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -522,6 +522,7 @@ public:
0;
}
ULONG GetNumberFormat( SCCOL nCol, SCROW nRow ) const;
+ sal_uInt32 GetNumberFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const;
void MergeSelectionPattern( ScMergePatternState& rState,
const ScMarkData& rMark, BOOL bDeep ) const;
void MergePatternArea( ScMergePatternState& rState, SCCOL nCol1, SCROW nRow1,
diff --git a/sc/sdi/formatsh.sdi b/sc/sdi/formatsh.sdi
index 31ccf5c8af84..8b84a7b730c6 100644
--- a/sc/sdi/formatsh.sdi
+++ b/sc/sdi/formatsh.sdi
@@ -117,11 +117,11 @@ interface FormatForSelection
SID_ATTR_NUMBERFORMAT_VALUE [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState;]
SID_NUMBER_FORMAT [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState;]
SID_NUMBER_TWODEC [ ExecMethod = ExecuteNumFormat;]
- SID_NUMBER_SCIENTIFIC [ ExecMethod = ExecuteNumFormat;]
- SID_NUMBER_DATE [ ExecMethod = ExecuteNumFormat;]
- SID_NUMBER_CURRENCY [ ExecMethod = ExecuteNumFormat;]
- SID_NUMBER_PERCENT [ ExecMethod = ExecuteNumFormat;]
- SID_NUMBER_TIME [ ExecMethod = ExecuteNumFormat;]
+ SID_NUMBER_SCIENTIFIC [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState; ]
+ SID_NUMBER_DATE [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState; ]
+ SID_NUMBER_CURRENCY [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState; ]
+ SID_NUMBER_PERCENT [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState; ]
+ SID_NUMBER_TIME [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState; ]
SID_NUMBER_STANDARD [ ExecMethod = ExecuteNumFormat;]
SID_NUMBER_INCDEC [ ExecMethod = ExecuteNumFormat;]
SID_NUMBER_DECDEC [ ExecMethod = ExecuteNumFormat;]
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index d3c76518c035..2e2b595137ef 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -354,6 +354,22 @@ const ScPatternAttr* ScColumn::GetMostUsedPattern( SCROW nStartRow, SCROW nEndRo
return pMaxPattern;
}
+sal_uInt32 ScColumn::GetNumberFormat( SCROW nStartRow, SCROW nEndRow ) const
+{
+ SCROW nPatStartRow, nPatEndRow;
+ const ScPatternAttr* pPattern = pAttrArray->GetPatternRange(nPatStartRow, nPatEndRow, nStartRow);
+ sal_uInt32 nFormat = pPattern->GetNumberFormat(pDocument->GetFormatTable());
+ while (nEndRow > nPatEndRow)
+ {
+ nStartRow = nPatEndRow + 1;
+ pPattern = pAttrArray->GetPatternRange(nPatStartRow, nPatEndRow, nStartRow);
+ sal_uInt32 nTmpFormat = pPattern->GetNumberFormat(pDocument->GetFormatTable());
+ if (nFormat != nTmpFormat)
+ return 0;
+ }
+ return nFormat;
+}
+
ULONG ScColumn::GetNumberFormat( SCROW nRow ) const
{
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 17763c909b47..aa1672aecd75 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -2723,6 +2723,32 @@ void ScDocument::GetNumberFormat( SCCOL nCol, SCROW nRow, SCTAB nTab,
rFormat = 0;
}
+sal_uInt32 ScDocument::GetNumberFormat( const ScRange& rRange ) const
+{
+ SCTAB nTab1 = rRange.aStart.Tab(), nTab2 = rRange.aEnd.Tab();
+ SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col();
+ SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
+
+ if (!ValidTab(nTab1) || !ValidTab(nTab2) || !pTab[nTab1] || !pTab[nTab2])
+ return 0;
+
+ sal_uInt32 nFormat = 0;
+ bool bFirstItem = true;
+ for (SCTAB nTab = nTab1; nTab <= nTab2; ++nTab)
+ for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
+ {
+ sal_uInt32 nThisFormat = pTab[nTab]->GetNumberFormat(nCol, nRow1, nRow2);
+ if (bFirstItem)
+ {
+ nFormat = nThisFormat;
+ bFirstItem = false;
+ }
+ else if (nThisFormat != nFormat)
+ return 0;
+ }
+
+ return nFormat;
+}
sal_uInt32 ScDocument::GetNumberFormat( const ScAddress& rPos ) const
{
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 66e385a13b85..eee6e6e72bb8 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1329,6 +1329,14 @@ ULONG ScTable::GetNumberFormat( SCCOL nCol, SCROW nRow ) const
return 0;
}
+sal_uInt32 ScTable::GetNumberFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const
+{
+ if (!ValidCol(nCol) || !ValidRow(nStartRow) || !ValidRow(nEndRow))
+ return 0;
+
+ return aCol[nCol].GetNumberFormat(nStartRow, nEndRow);
+}
+
const ScPatternAttr* ScTable::GetPattern( SCCOL nCol, SCROW nRow ) const
{
diff --git a/sc/source/ui/inc/formatsh.hxx b/sc/source/ui/inc/formatsh.hxx
index e45fb99c54ef..689e6da6e22f 100644
--- a/sc/source/ui/inc/formatsh.hxx
+++ b/sc/source/ui/inc/formatsh.hxx
@@ -74,6 +74,9 @@ public:
void ExecFormatPaintbrush( SfxRequest& rReq );
void StateFormatPaintbrush( SfxItemSet& rSet );
+
+private:
+ short GetCurrentNumberFormatType();
};
#endif
diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx
index 12a1bb87211b..3b809c9d65aa 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -55,6 +55,7 @@
#include <sfx2/app.hxx>
#include <sfx2/viewfrm.hxx>
+#include <sfx2/bindings.hxx>
#include <sfx2/objface.hxx>
#include <sfx2/request.hxx>
#include <svl/whiter.hxx>
@@ -925,6 +926,7 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
const SfxItemSet* pReqArgs = rReq.GetArgs();
USHORT nSlot = rReq.GetSlot();
+ SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
@@ -957,6 +959,8 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
}
}
+ short nType = GetCurrentNumberFormatType();
+ SfxItemSet aSet( GetPool(), nSlot, nSlot );
switch ( nSlot )
{
case SID_NUMBER_TWODEC:
@@ -964,23 +968,48 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
rReq.Done();
break;
case SID_NUMBER_SCIENTIFIC:
- pTabViewShell->SetNumberFormat( NUMBERFORMAT_SCIENTIFIC );
+ if ((nType & NUMBERFORMAT_SCIENTIFIC))
+ pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
+ else
+ pTabViewShell->SetNumberFormat( NUMBERFORMAT_SCIENTIFIC );
+ aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_SCIENTIFIC)) );
+ rBindings.Invalidate( nSlot );
rReq.Done();
break;
case SID_NUMBER_DATE:
- pTabViewShell->SetNumberFormat( NUMBERFORMAT_DATE );
+ if ((nType & NUMBERFORMAT_DATE))
+ pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
+ else
+ pTabViewShell->SetNumberFormat( NUMBERFORMAT_DATE );
+ aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_DATE)) );
+ rBindings.Invalidate( nSlot );
rReq.Done();
break;
case SID_NUMBER_TIME:
- pTabViewShell->SetNumberFormat( NUMBERFORMAT_TIME );
+ if ((nType & NUMBERFORMAT_TIME))
+ pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
+ else
+ pTabViewShell->SetNumberFormat( NUMBERFORMAT_TIME );
+ aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_TIME)) );
+ rBindings.Invalidate( nSlot );
rReq.Done();
break;
case SID_NUMBER_CURRENCY:
- pTabViewShell->SetNumberFormat( NUMBERFORMAT_CURRENCY );
+ if ((nType & NUMBERFORMAT_CURRENCY))
+ pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
+ else
+ pTabViewShell->SetNumberFormat( NUMBERFORMAT_CURRENCY );
+ aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_CURRENCY)) );
+ rBindings.Invalidate( nSlot );
rReq.Done();
break;
case SID_NUMBER_PERCENT:
- pTabViewShell->SetNumberFormat( NUMBERFORMAT_PERCENT );
+ if ((nType & NUMBERFORMAT_PERCENT))
+ pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
+ else
+ pTabViewShell->SetNumberFormat( NUMBERFORMAT_PERCENT );
+ aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_PERCENT)) );
+ rBindings.Invalidate( nSlot );
rReq.Done();
break;
case SID_NUMBER_STANDARD:
@@ -1986,9 +2015,8 @@ void ScFormatShell::GetAlignState( SfxItemSet& rSet )
void ScFormatShell::GetNumFormatState( SfxItemSet& rSet )
{
ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
-
- // ScViewData* pViewData = GetViewData();
- ScDocument* pDoc = pViewData->GetDocument();
+ ScDocument* pDoc = pViewData->GetDocument();
+ short nType = GetCurrentNumberFormatType();
SfxWhichIter aIter(rSet);
USHORT nWhich = aIter.FirstWhich();
@@ -2015,7 +2043,21 @@ void ScFormatShell::GetNumFormatState( SfxItemSet& rSet )
rSet.Put( SfxStringItem( nWhich, aFormatCode ) );
}
break;
-
+ case SID_NUMBER_SCIENTIFIC:
+ rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_SCIENTIFIC)) );
+ break;
+ case SID_NUMBER_DATE:
+ rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_DATE)) );
+ break;
+ case SID_NUMBER_CURRENCY:
+ rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_CURRENCY)) );
+ break;
+ case SID_NUMBER_PERCENT:
+ rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_PERCENT)) );
+ break;
+ case SID_NUMBER_TIME:
+ rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_TIME)) );
+ break;
}
nWhich = aIter.NextWhich();
}
@@ -2166,3 +2208,67 @@ void ScFormatShell::StateFormatPaintbrush( SfxItemSet& rSet )
rSet.Put( SfxBoolItem( SID_FORMATPAINTBRUSH, pViewData->GetView()->HasPaintBrush() ) );
}
+short ScFormatShell::GetCurrentNumberFormatType()
+{
+ short nType = NUMBERFORMAT_ALL;
+ ScDocument* pDoc = GetViewData()->GetDocument();
+ ScMarkData aMark(GetViewData()->GetMarkData());
+ const SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
+ if (!pFormatter)
+ return nType;
+
+ // TODO: Find out how to get a selected table range in case multiple tables
+ // are selected. Currently we only check for the current active table.
+
+ if ( aMark.IsMarked() || aMark.IsMultiMarked() )
+ {
+ aMark.MarkToMulti();
+ ScRange aRange;
+ aMark.GetMultiMarkArea(aRange);
+
+ const ScMarkArray* pArray = aMark.GetArray();
+ if (!pArray)
+ return nType;
+
+ short nComboType = NUMBERFORMAT_ALL;
+ bool bFirstItem = true;
+ for (SCCOL nCol = aRange.aStart.Col(); nCol <= aRange.aEnd.Col(); ++nCol)
+ {
+ const ScMarkArray& rColArray = pArray[nCol];
+ if (!rColArray.HasMarks())
+ continue;
+
+ SCROW nRow1, nRow2;
+ ScMarkArrayIter aMarkIter(&rColArray);
+ while (aMarkIter.Next(nRow1, nRow2))
+ {
+ ScRange aColRange(nCol, nRow1, aRange.aStart.Tab());
+ aColRange.aEnd.SetRow(nRow2);
+ sal_uInt32 nNumFmt = pDoc->GetNumberFormat(aColRange);
+ const SvNumberformat* pEntry = pFormatter->GetEntry(nNumFmt);
+ if (!pEntry)
+ return 0;
+
+ short nThisType = pEntry->GetType();
+ if (bFirstItem)
+ {
+ bFirstItem = false;
+ nComboType = nThisType;
+ }
+ else if (nComboType != nThisType)
+ // mixed number format type.
+ return NUMBERFORMAT_ALL;
+ }
+ }
+ nType = nComboType;
+ }
+ else
+ {
+ sal_uInt32 nNumFmt;
+ pDoc->GetNumberFormat( pViewData->GetCurX(), pViewData->GetCurY(),
+ pViewData->GetTabNo(), nNumFmt );
+ const SvNumberformat* pEntry = pFormatter->GetEntry( nNumFmt );
+ nType = pEntry ? pEntry->GetType() : 0;
+ }
+ return nType;
+}
diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index 90bfe0c24e5c..5d48f3e60b1f 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -264,6 +264,13 @@ void ScTabView::InvalidateAttribs()
rBindings.Invalidate( SID_ALIGN_ANY_VCENTER );
rBindings.Invalidate( SID_ALIGN_ANY_BOTTOM );
+ rBindings.Invalidate( SID_NUMBER_CURRENCY );
+ rBindings.Invalidate( SID_NUMBER_SCIENTIFIC );
+ rBindings.Invalidate( SID_NUMBER_DATE );
+ rBindings.Invalidate( SID_NUMBER_CURRENCY );
+ rBindings.Invalidate( SID_NUMBER_PERCENT );
+ rBindings.Invalidate( SID_NUMBER_TIME );
+
// rBindings.Invalidate( SID_RANGE_VALUE );
// rBindings.Invalidate( SID_RANGE_FORMULA );
}
diff --git a/sc/uiconfig/scalc/toolbar/formatobjectbar.xml b/sc/uiconfig/scalc/toolbar/formatobjectbar.xml
index 13b6abcf9bcf..49c31d72f176 100644
--- a/sc/uiconfig/scalc/toolbar/formatobjectbar.xml
+++ b/sc/uiconfig/scalc/toolbar/formatobjectbar.xml
@@ -33,7 +33,7 @@
<toolbar:toolbaritem xlink:href=".uno:NumberFormatPercent" toolbar:helpid="helpid:26046" />
<toolbar:toolbaritem xlink:href=".uno:NumberFormatDate" toolbar:helpid="helpid:26053" toolbar:visible="false" />
<toolbar:toolbaritem xlink:href=".uno:NumberFormatScientific" toolbar:helpid="helpid:26055" toolbar:visible="false" />
- <toolbar:toolbaritem xlink:href=".uno:NumberFormatStandard" toolbar:helpid="helpid:26052" />
+ <toolbar:toolbaritem xlink:href=".uno:NumberFormatStandard" toolbar:helpid="helpid:26052" toolbar:visible="false" />
<toolbar:toolbaritem xlink:href=".uno:NumberFormatIncDecimals" toolbar:helpid="helpid:26057" />
<toolbar:toolbaritem xlink:href=".uno:NumberFormatDecDecimals" toolbar:helpid="helpid:26058" />
<toolbar:toolbarseparator/>