1 diff --git sc/inc/column.hxx sc/inc/column.hxx
2 index 26e4a45..48b44af 100644
5 @@ -298,6 +298,7 @@ public:
6 const ScPatternAttr* GetMostUsedPattern( SCROW nStartRow, SCROW nEndRow ) const;
8 ULONG GetNumberFormat( SCROW nRow ) const;
9 + sal_uInt32 GetNumberFormat( SCROW nStartRow, SCROW nEndRow ) const;
11 void MergeSelectionPattern( ScMergePatternState& rState, const ScMarkData& rMark, BOOL bDeep ) const;
12 void MergePatternArea( ScMergePatternState& rState, SCROW nRow1, SCROW nRow2, BOOL bDeep ) const;
13 diff --git sc/inc/document.hxx sc/inc/document.hxx
14 index b4844a1..dea8da9 100644
15 --- sc/inc/document.hxx
16 +++ sc/inc/document.hxx
17 @@ -736,6 +736,7 @@ public:
18 SC_DLLPUBLIC double RoundValueAsShown( double fVal, ULONG nFormat );
19 SC_DLLPUBLIC void GetNumberFormat( SCCOL nCol, SCROW nRow, SCTAB nTab,
20 sal_uInt32& rFormat );
21 + sal_uInt32 GetNumberFormat( const ScRange& rRange ) const;
22 SC_DLLPUBLIC sal_uInt32 GetNumberFormat( const ScAddress& ) const;
23 /** If no number format attribute is set and the cell
24 pointer passed is of type formula cell, the calculated
25 diff --git sc/inc/table.hxx sc/inc/table.hxx
26 index 2378728..216a876 100644
29 @@ -433,6 +433,7 @@ public:
30 ULONG GetNumberFormat( const ScAddress& rPos ) const
31 { return aCol[rPos.Col()].GetNumberFormat( rPos.Row() ); }
32 ULONG GetNumberFormat( SCCOL nCol, SCROW nRow ) const;
33 + sal_uInt32 GetNumberFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const;
34 void MergeSelectionPattern( ScMergePatternState& rState,
35 const ScMarkData& rMark, BOOL bDeep ) const;
36 void MergePatternArea( ScMergePatternState& rState, SCCOL nCol1, SCROW nRow1,
37 diff --git sc/sdi/formatsh.sdi sc/sdi/formatsh.sdi
38 index a7bd57a..ed57de4 100644
39 --- sc/sdi/formatsh.sdi
40 +++ sc/sdi/formatsh.sdi
41 @@ -120,11 +120,11 @@ interface FormatForSelection
42 SID_ATTR_NUMBERFORMAT_VALUE [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState;]
43 SID_NUMBER_FORMAT [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState;]
44 SID_NUMBER_TWODEC [ ExecMethod = ExecuteNumFormat;]
45 - SID_NUMBER_SCIENTIFIC [ ExecMethod = ExecuteNumFormat;]
46 - SID_NUMBER_DATE [ ExecMethod = ExecuteNumFormat;]
47 - SID_NUMBER_CURRENCY [ ExecMethod = ExecuteNumFormat;]
48 - SID_NUMBER_PERCENT [ ExecMethod = ExecuteNumFormat;]
49 - SID_NUMBER_TIME [ ExecMethod = ExecuteNumFormat;]
50 + SID_NUMBER_SCIENTIFIC [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState; ]
51 + SID_NUMBER_DATE [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState; ]
52 + SID_NUMBER_CURRENCY [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState; ]
53 + SID_NUMBER_PERCENT [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState; ]
54 + SID_NUMBER_TIME [ ExecMethod = ExecuteNumFormat; StateMethod = GetNumFormatState; ]
55 SID_NUMBER_STANDARD [ ExecMethod = ExecuteNumFormat;]
56 SID_NUMBER_INCDEC [ ExecMethod = ExecuteNumFormat;]
57 SID_NUMBER_DECDEC [ ExecMethod = ExecuteNumFormat;]
58 diff --git sc/source/core/data/column.cxx sc/source/core/data/column.cxx
59 index b714fec..bc0fc1d 100644
60 --- sc/source/core/data/column.cxx
61 +++ sc/source/core/data/column.cxx
62 @@ -362,6 +362,22 @@ const ScPatternAttr* ScColumn::GetMostUsedPattern( SCROW nStartRow, SCROW nEndRo
66 +sal_uInt32 ScColumn::GetNumberFormat( SCROW nStartRow, SCROW nEndRow ) const
68 + SCROW nPatStartRow, nPatEndRow;
69 + const ScPatternAttr* pPattern = pAttrArray->GetPatternRange(nPatStartRow, nPatEndRow, nStartRow);
70 + sal_uInt32 nFormat = pPattern->GetNumberFormat(pDocument->GetFormatTable());
71 + while (nEndRow > nPatEndRow)
73 + nStartRow = nPatEndRow + 1;
74 + pPattern = pAttrArray->GetPatternRange(nPatStartRow, nPatEndRow, nStartRow);
75 + sal_uInt32 nTmpFormat = pPattern->GetNumberFormat(pDocument->GetFormatTable());
76 + if (nFormat != nTmpFormat)
83 ULONG ScColumn::GetNumberFormat( SCROW nRow ) const
85 diff --git sc/source/core/data/document.cxx sc/source/core/data/document.cxx
86 index 5844fa0..bf0afb3 100644
87 --- sc/source/core/data/document.cxx
88 +++ sc/source/core/data/document.cxx
89 @@ -2276,6 +2276,32 @@ void ScDocument::GetNumberFormat( SCCOL nCol, SCROW nRow, SCTAB nTab,
93 +sal_uInt32 ScDocument::GetNumberFormat( const ScRange& rRange ) const
95 + SCTAB nTab1 = rRange.aStart.Tab(), nTab2 = rRange.aEnd.Tab();
96 + SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col();
97 + SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row();
99 + if (!ValidTab(nTab1) || !ValidTab(nTab2) || !pTab[nTab1] || !pTab[nTab2])
102 + sal_uInt32 nFormat = 0;
103 + bool bFirstItem = true;
104 + for (SCTAB nTab = nTab1; nTab <= nTab2; ++nTab)
105 + for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
107 + sal_uInt32 nThisFormat = pTab[nTab]->GetNumberFormat(nCol, nRow1, nRow2);
110 + nFormat = nThisFormat;
111 + bFirstItem = false;
113 + else if (nThisFormat != nFormat)
120 sal_uInt32 ScDocument::GetNumberFormat( const ScAddress& rPos ) const
122 diff --git sc/source/core/data/table2.cxx sc/source/core/data/table2.cxx
123 index 678b7a0..d448214 100644
124 --- sc/source/core/data/table2.cxx
125 +++ sc/source/core/data/table2.cxx
126 @@ -1104,6 +1104,14 @@ ULONG ScTable::GetNumberFormat( SCCOL nCol, SCROW nRow ) const
130 +sal_uInt32 ScTable::GetNumberFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow ) const
132 + if (!ValidCol(nCol) || !ValidRow(nStartRow) || !ValidRow(nEndRow))
135 + return aCol[nCol].GetNumberFormat(nStartRow, nEndRow);
139 const ScPatternAttr* ScTable::GetPattern( SCCOL nCol, SCROW nRow ) const
141 diff --git sc/source/ui/inc/formatsh.hxx sc/source/ui/inc/formatsh.hxx
142 index c67f110..5bbece4 100644
143 --- sc/source/ui/inc/formatsh.hxx
144 +++ sc/source/ui/inc/formatsh.hxx
145 @@ -77,6 +77,9 @@ public:
147 void ExecFormatPaintbrush( SfxRequest& rReq );
148 void StateFormatPaintbrush( SfxItemSet& rSet );
151 + short GetCurrentNumberFormatType();
155 diff --git sc/source/ui/view/formatsh.cxx sc/source/ui/view/formatsh.cxx
156 index d36a262..72db244 100644
157 --- sc/source/ui/view/formatsh.cxx
158 +++ sc/source/ui/view/formatsh.cxx
161 #include <sfx2/app.hxx>
162 #include <sfx2/viewfrm.hxx>
163 +#include <sfx2/bindings.hxx>
164 #include <sfx2/objface.hxx>
165 #include <sfx2/request.hxx>
166 #include <svtools/whiter.hxx>
167 @@ -919,6 +920,7 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
168 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
169 const SfxItemSet* pReqArgs = rReq.GetArgs();
170 USHORT nSlot = rReq.GetSlot();
171 + SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
173 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
175 @@ -951,6 +953,8 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
179 + short nType = GetCurrentNumberFormatType();
180 + SfxItemSet aSet( GetPool(), nSlot, nSlot );
183 case SID_NUMBER_TWODEC:
184 @@ -958,23 +962,48 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq )
187 case SID_NUMBER_SCIENTIFIC:
188 - pTabViewShell->SetNumberFormat( NUMBERFORMAT_SCIENTIFIC );
189 + if ((nType & NUMBERFORMAT_SCIENTIFIC))
190 + pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
192 + pTabViewShell->SetNumberFormat( NUMBERFORMAT_SCIENTIFIC );
193 + aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_SCIENTIFIC)) );
194 + rBindings.Invalidate( nSlot );
197 case SID_NUMBER_DATE:
198 - pTabViewShell->SetNumberFormat( NUMBERFORMAT_DATE );
199 + if ((nType & NUMBERFORMAT_DATE))
200 + pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
202 + pTabViewShell->SetNumberFormat( NUMBERFORMAT_DATE );
203 + aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_DATE)) );
204 + rBindings.Invalidate( nSlot );
207 case SID_NUMBER_TIME:
208 - pTabViewShell->SetNumberFormat( NUMBERFORMAT_TIME );
209 + if ((nType & NUMBERFORMAT_TIME))
210 + pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
212 + pTabViewShell->SetNumberFormat( NUMBERFORMAT_TIME );
213 + aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_TIME)) );
214 + rBindings.Invalidate( nSlot );
217 case SID_NUMBER_CURRENCY:
218 - pTabViewShell->SetNumberFormat( NUMBERFORMAT_CURRENCY );
219 + if ((nType & NUMBERFORMAT_CURRENCY))
220 + pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
222 + pTabViewShell->SetNumberFormat( NUMBERFORMAT_CURRENCY );
223 + aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_CURRENCY)) );
224 + rBindings.Invalidate( nSlot );
227 case SID_NUMBER_PERCENT:
228 - pTabViewShell->SetNumberFormat( NUMBERFORMAT_PERCENT );
229 + if ((nType & NUMBERFORMAT_PERCENT))
230 + pTabViewShell->SetNumberFormat( NUMBERFORMAT_NUMBER );
232 + pTabViewShell->SetNumberFormat( NUMBERFORMAT_PERCENT );
233 + aSet.Put( SfxBoolItem(nSlot, !(nType & NUMBERFORMAT_PERCENT)) );
234 + rBindings.Invalidate( nSlot );
237 case SID_NUMBER_STANDARD:
238 @@ -1975,9 +2004,8 @@ void ScFormatShell::GetAlignState( SfxItemSet& rSet )
239 void ScFormatShell::GetNumFormatState( SfxItemSet& rSet )
241 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
243 - // ScViewData* pViewData = GetViewData();
244 - ScDocument* pDoc = pViewData->GetDocument();
245 + ScDocument* pDoc = pViewData->GetDocument();
246 + short nType = GetCurrentNumberFormatType();
248 SfxWhichIter aIter(rSet);
249 USHORT nWhich = aIter.FirstWhich();
250 @@ -2004,7 +2032,21 @@ void ScFormatShell::GetNumFormatState( SfxItemSet& rSet )
251 rSet.Put( SfxStringItem( nWhich, aFormatCode ) );
255 + case SID_NUMBER_SCIENTIFIC:
256 + rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_SCIENTIFIC)) );
258 + case SID_NUMBER_DATE:
259 + rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_DATE)) );
261 + case SID_NUMBER_CURRENCY:
262 + rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_CURRENCY)) );
264 + case SID_NUMBER_PERCENT:
265 + rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_PERCENT)) );
267 + case SID_NUMBER_TIME:
268 + rSet.Put( SfxBoolItem(nWhich, (nType & NUMBERFORMAT_TIME)) );
271 nWhich = aIter.NextWhich();
273 @@ -2155,3 +2197,68 @@ void ScFormatShell::StateFormatPaintbrush( SfxItemSet& rSet )
274 rSet.Put( SfxBoolItem( SID_FORMATPAINTBRUSH, pViewData->GetView()->HasPaintBrush() ) );
277 +short ScFormatShell::GetCurrentNumberFormatType()
279 + short nType = NUMBERFORMAT_ALL;
280 + ScDocument* pDoc = GetViewData()->GetDocument();
281 + ScMarkData aMark(GetViewData()->GetMarkData());
282 + const SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
286 + // TODO: Find out how to get a selected table range in case multiple tables
287 + // are selected. Currently we only check for the current active table.
289 + if ( aMark.IsMarked() || aMark.IsMultiMarked() )
291 + aMark.MarkToMulti();
293 + aMark.GetMultiMarkArea(aRange);
295 + const ScMarkArray* pArray = aMark.GetArray();
299 + short nComboType = NUMBERFORMAT_ALL;
300 + bool bFirstItem = true;
301 + for (SCCOL nCol = aRange.aStart.Col(); nCol <= aRange.aEnd.Col(); ++nCol)
303 + const ScMarkArray& rColArray = pArray[nCol];
304 + if (!rColArray.HasMarks())
307 + SCROW nRow1, nRow2;
308 + ScMarkArrayIter aMarkIter(&rColArray);
309 + while (aMarkIter.Next(nRow1, nRow2))
311 + ScRange aColRange(nCol, nRow1, aRange.aStart.Tab());
312 + aColRange.aEnd.SetRow(nRow2);
313 + sal_uInt32 nNumFmt = pDoc->GetNumberFormat(aColRange);
314 + const SvNumberformat* pEntry = pFormatter->GetEntry(nNumFmt);
318 + short nThisType = pEntry->GetType();
321 + bFirstItem = false;
322 + nComboType = nThisType;
324 + else if (nComboType != nThisType)
325 + // mixed number format type.
326 + return NUMBERFORMAT_ALL;
329 + nType = nComboType;
333 + sal_uInt32 nNumFmt;
334 + pDoc->GetNumberFormat( pViewData->GetCurX(), pViewData->GetCurY(),
335 + pViewData->GetTabNo(), nNumFmt );
336 + const SvNumberformat* pEntry = pFormatter->GetEntry( nNumFmt );
337 + nType = pEntry ? pEntry->GetType() : 0;
342 diff --git sc/source/ui/view/tabview3.cxx sc/source/ui/view/tabview3.cxx
343 index f2c10c8..edf4c95 100644
344 --- sc/source/ui/view/tabview3.cxx
345 +++ sc/source/ui/view/tabview3.cxx
346 @@ -267,6 +267,13 @@ void ScTabView::InvalidateAttribs()
347 rBindings.Invalidate( SID_ALIGN_ANY_VCENTER );
348 rBindings.Invalidate( SID_ALIGN_ANY_BOTTOM );
350 + rBindings.Invalidate( SID_NUMBER_CURRENCY );
351 + rBindings.Invalidate( SID_NUMBER_SCIENTIFIC );
352 + rBindings.Invalidate( SID_NUMBER_DATE );
353 + rBindings.Invalidate( SID_NUMBER_CURRENCY );
354 + rBindings.Invalidate( SID_NUMBER_PERCENT );
355 + rBindings.Invalidate( SID_NUMBER_TIME );
357 // rBindings.Invalidate( SID_RANGE_VALUE );
358 // rBindings.Invalidate( SID_RANGE_FORMULA );
360 diff --git sc/uiconfig/scalc/toolbar/formatobjectbar.xml sc/uiconfig/scalc/toolbar/formatobjectbar.xml
361 index 13b6abc..49c31d7 100644
362 --- sc/uiconfig/scalc/toolbar/formatobjectbar.xml
363 +++ sc/uiconfig/scalc/toolbar/formatobjectbar.xml
365 <toolbar:toolbaritem xlink:href=".uno:NumberFormatPercent" toolbar:helpid="helpid:26046" />
366 <toolbar:toolbaritem xlink:href=".uno:NumberFormatDate" toolbar:helpid="helpid:26053" toolbar:visible="false" />
367 <toolbar:toolbaritem xlink:href=".uno:NumberFormatScientific" toolbar:helpid="helpid:26055" toolbar:visible="false" />
368 - <toolbar:toolbaritem xlink:href=".uno:NumberFormatStandard" toolbar:helpid="helpid:26052" />
369 + <toolbar:toolbaritem xlink:href=".uno:NumberFormatStandard" toolbar:helpid="helpid:26052" toolbar:visible="false" />
370 <toolbar:toolbaritem xlink:href=".uno:NumberFormatIncDecimals" toolbar:helpid="helpid:26057" />
371 <toolbar:toolbaritem xlink:href=".uno:NumberFormatDecDecimals" toolbar:helpid="helpid:26058" />
372 <toolbar:toolbarseparator/>