[Libreoffice-commits] core.git: 9 commits - officecfg/registry sc/inc sc/Library_sc.mk sc/sdi sc/source sc/uiconfig sc/UIConfig_scalc.mk

Tomaž Vajngerl quikee at gmail.com
Mon Nov 11 14:23:25 PST 2013


 officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu |   16 
 sc/Library_sc.mk                                                  | 1146 +++++-----
 sc/UIConfig_scalc.mk                                              |    4 
 sc/inc/sc.hrc                                                     |    2 
 sc/sdi/cellsh.sdi                                                 |    2 
 sc/sdi/scalc.sdi                                                  |   48 
 sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx       |  359 +--
 sc/source/ui/StatisticsDialogs/CorrelationDialog.cxx              |  132 -
 sc/source/ui/StatisticsDialogs/CovarianceDialog.cxx               |  131 -
 sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx    |  110 
 sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx     |  128 +
 sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator.cxx      |  134 +
 sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx            |  117 +
 sc/source/ui/StatisticsDialogs/StatisticsDialogs.hrc              |    2 
 sc/source/ui/StatisticsDialogs/StatisticsDialogs.src              |   14 
 sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx    |   34 
 sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx |  322 ++
 sc/source/ui/app/scdll.cxx                                        |    5 
 sc/source/ui/inc/AnalysisOfVarianceDialog.hxx                     |    8 
 sc/source/ui/inc/CorrelationDialog.hxx                            |   23 
 sc/source/ui/inc/CovarianceDialog.hxx                             |   22 
 sc/source/ui/inc/DescriptiveStatisticsDialog.hxx                  |    3 
 sc/source/ui/inc/ExponentialSmoothingDialog.hxx                   |   46 
 sc/source/ui/inc/MatrixComparisonGenerator.hxx                    |   45 
 sc/source/ui/inc/MovingAverageDialog.hxx                          |   46 
 sc/source/ui/inc/StatisticsInputOutputDialog.hxx                  |   19 
 sc/source/ui/inc/TableFillingAndNavigationTools.hxx               |  150 +
 sc/source/ui/inc/reffact.hxx                                      |   15 
 sc/source/ui/view/cellsh1.cxx                                     |   19 
 sc/source/ui/view/tabvwsh.cxx                                     |    2 
 sc/source/ui/view/tabvwshc.cxx                                    |   14 
 sc/uiconfig/scalc/menubar/menubar.xml                             |    2 
 sc/uiconfig/scalc/ui/analysisofvariancedialog.ui                  |  146 +
 sc/uiconfig/scalc/ui/correlationdialog.ui                         |  262 ++
 sc/uiconfig/scalc/ui/covariancedialog.ui                          |  262 ++
 sc/uiconfig/scalc/ui/descriptivestatisticsdialog.ui               |   79 
 sc/uiconfig/scalc/ui/exponentialsmoothingdialog.ui                |  343 ++
 sc/uiconfig/scalc/ui/movingaveragedialog.ui                       |  342 ++
 38 files changed, 3432 insertions(+), 1122 deletions(-)

New commits:
commit 1b4c3fad813a2673f14f88fcb8876e1bef118c6e
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Sun Nov 10 18:05:29 2013 +0100

    Simplification and better output of statistics dialogs.
    
    Change-Id: Ia21bb07f7721a7697807f8ee98706bd3fc136653

diff --git a/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
index 4257165..7c3873b 100644
--- a/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
@@ -87,17 +87,20 @@ sal_Bool ScAnalysisOfVarianceDialog::Close()
     return DoClose( ScAnalysisOfVarianceDialogWrapper::GetChildWindowId() );
 }
 
-void ScAnalysisOfVarianceDialog::CalculateInputAndWriteToOutput( )
+sal_Int16 ScAnalysisOfVarianceDialog::GetUndoNameId()
 {
-    OUString aUndo( SC_STRLOAD( RID_STATISTICS_DLGS, STR_ANALYSIS_OF_VARIANCE_UNDO_NAME));
-
-    ScDocShell* pDocShell = mViewData->GetDocShell();
-    svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
-    pUndoManager->EnterListAction( aUndo, aUndo );
+    return STR_ANALYSIS_OF_VARIANCE_UNDO_NAME;
+}
 
+ScRange ScAnalysisOfVarianceDialog::ApplyOutput(ScDocShell* pDocShell)
+{
     AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument);
     FormulaTemplate aTemplate(mDocument, mAddressDetails);
 
+    output.writeBoldString("ANOVA - Single Factor");
+    output.nextRow();
+    output.nextRow();
+
     // Write labels
     for(sal_Int32 i = 0; lclBasicStatisticsLabels[i] != NULL; i++)
     {
@@ -114,7 +117,7 @@ void ScAnalysisOfVarianceDialog::CalculateInputAndWriteToOutput( )
     else
         pIterator.reset(new DataRangeByRowIterator(mInputRange));
 
-    // Write statistic formulas for columns
+    // Write statistic formulas for rows/columns
     for( ; pIterator->hasNext(); pIterator->next() )
     {
         output.resetColumn();
@@ -124,7 +127,7 @@ void ScAnalysisOfVarianceDialog::CalculateInputAndWriteToOutput( )
         else
             aTemplate.setTemplate(strRowLabelTemplate);
 
-        aTemplate.applyString(strWildcardNumber, OUString::number(pIterator->index() + 1));
+        aTemplate.applyNumber(strWildcardNumber, pIterator->index() + 1);
         pDocShell->GetDocFunc().SetStringCell(output.current(), aTemplate.getTemplate(), true);
         output.nextColumn();
 
@@ -260,9 +263,7 @@ void ScAnalysisOfVarianceDialog::CalculateInputAndWriteToOutput( )
     }
     output.nextRow();
 
-    ScRange aOutputRange(output.mMinimumAddress, output.mMaximumAddress);
-    pUndoManager->LeaveListAction();
-    pDocShell->PostPaint( aOutputRange, PAINT_GRID );
+    return ScRange(output.mMinimumAddress, output.mMaximumAddress);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx b/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
index d9a18a0..2fc1b55 100644
--- a/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
@@ -56,7 +56,9 @@ static const StatisticCalculation lclCalcDefinitions[] =
 };
 
 static const OUString strWildcardRange("%RANGE%");
-
+static const OUString strWildcardNumber("%NUMBER%");
+static const OUString strColumnLabelTemplate("Column %NUMBER%");
+static const OUString strRowLabelTemplate("Row %NUMBER%");
 }
 
 ScDescriptiveStatisticsDialog::ScDescriptiveStatisticsDialog(
@@ -75,18 +77,42 @@ sal_Bool ScDescriptiveStatisticsDialog::Close()
     return DoClose( ScDescriptiveStatisticsDialogWrapper::GetChildWindowId() );
 }
 
-void ScDescriptiveStatisticsDialog::CalculateInputAndWriteToOutput( )
+sal_Int16 ScDescriptiveStatisticsDialog::GetUndoNameId()
 {
-    OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, STR_DESCRIPTIVE_STATISTICS_UNDO_NAME));
-    ScDocShell* pDocShell = mViewData->GetDocShell();
-    svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
-    pUndoManager->EnterListAction( aUndo, aUndo );
+    return STR_DESCRIPTIVE_STATISTICS_UNDO_NAME;
+}
 
+ScRange ScDescriptiveStatisticsDialog::ApplyOutput(ScDocShell* pDocShell)
+{
     OUString aReferenceString;
 
     AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument);
     FormulaTemplate aTemplate(mDocument, mAddressDetails);
 
+    boost::scoped_ptr<DataRangeIterator> pIterator;
+    if (mGroupedBy == BY_COLUMN)
+        pIterator.reset(new DataRangeByColumnIterator(mInputRange));
+    else
+        pIterator.reset(new DataRangeByRowIterator(mInputRange));
+
+    aOutput.nextColumn();
+
+    // Write column/row labels
+    for( ; pIterator->hasNext(); pIterator->next() )
+    {
+        if (mGroupedBy == BY_COLUMN)
+            aTemplate.setTemplate(strColumnLabelTemplate);
+        else
+            aTemplate.setTemplate(strRowLabelTemplate);
+        aTemplate.applyNumber(strWildcardNumber, pIterator->index() + 1);
+        aOutput.writeBoldString(aTemplate.getTemplate());
+        aOutput.nextColumn();
+    }
+    aOutput.nextRow();
+    aOutput.resetColumn();
+    aOutput.push();
+
+    // Write calculation labels
     for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
     {
         OUString aLabel(SC_STRLOAD(RID_STATISTICS_DLGS, lclCalcDefinitions[i].aCalculationNameId));
@@ -95,11 +121,7 @@ void ScDescriptiveStatisticsDialog::CalculateInputAndWriteToOutput( )
     }
     aOutput.nextColumn();
 
-    boost::scoped_ptr<DataRangeIterator> pIterator;
-    if (mGroupedBy == BY_COLUMN)
-        pIterator.reset(new DataRangeByColumnIterator(mInputRange));
-    else
-        pIterator.reset(new DataRangeByRowIterator(mInputRange));
+    pIterator->reset();
 
     for( ; pIterator->hasNext(); pIterator->next() )
     {
@@ -115,9 +137,7 @@ void ScDescriptiveStatisticsDialog::CalculateInputAndWriteToOutput( )
         aOutput.nextColumn();
     }
 
-    pUndoManager->LeaveListAction();
-    ScRange aOutputRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
-    pDocShell->PostPaint( aOutputRange, PAINT_GRID );
+    return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx b/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
index 34cfcf4..9e4cb9b 100644
--- a/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
@@ -45,19 +45,24 @@ sal_Bool ScExponentialSmoothingDialog::Close()
     return DoClose( ScExponentialSmoothingDialogWrapper::GetChildWindowId() );
 }
 
-void ScExponentialSmoothingDialog::CalculateInputAndWriteToOutput( )
+sal_Int16 ScExponentialSmoothingDialog::GetUndoNameId()
 {
-    OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, STR_EXPONENTIAL_SMOOTHING_UNDO_NAME));
-    ScDocShell* pDocShell = mViewData->GetDocShell();
-    svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
-    pUndoManager->EnterListAction( aUndo, aUndo );
+    return STR_EXPONENTIAL_SMOOTHING_UNDO_NAME;
+}
 
+ScRange ScExponentialSmoothingDialog::ApplyOutput(ScDocShell* pDocShell)
+{
     AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument);
     FormulaTemplate aTemplate(mDocument, mAddressDetails);
 
     // Smoothing factor
     double aSmoothingFactor = mpSmoothingFactor->GetValue() / 100.0;
 
+    // Alpha
+    output.writeBoldString("Alpha");
+    output.nextRow();
+
+    // Alpha Value
     ScAddress aSmoothingFactorAddress = output.current();
     output.writeValue(aSmoothingFactor);
     output.nextRow();
@@ -77,6 +82,16 @@ void ScExponentialSmoothingDialog::CalculateInputAndWriteToOutput( )
 
         ScRange aCurrentRange = pIterator->get();
 
+        // Write column label
+        if (mGroupedBy == BY_COLUMN)
+            aTemplate.setTemplate("Column %NUMBER%");
+        else
+            aTemplate.setTemplate("Row %NUMBER%");
+        aTemplate.applyNumber("%NUMBER%", pIterator->index() + 1);
+        output.writeBoldString(aTemplate.getTemplate());
+        output.nextRow();
+
+        // Initial value
         if (false)
         {
             aTemplate.setTemplate("=AVERAGE(%RANGE%)");
@@ -107,9 +122,7 @@ void ScExponentialSmoothingDialog::CalculateInputAndWriteToOutput( )
         output.nextColumn();
     }
 
-    pUndoManager->LeaveListAction();
-    ScRange aOutputRange(output.mMinimumAddress, output.mMaximumAddress);
-    pDocShell->PostPaint( aOutputRange, PAINT_GRID );
+    return ScRange (output.mMinimumAddress, output.mMaximumAddress);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator.cxx b/sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator.cxx
index b22a66a..07a7589 100644
--- a/sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator.cxx
+++ b/sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator.cxx
@@ -71,13 +71,13 @@ ScMatrixComparisonGenerator::ScMatrixComparisonGenerator(
 ScMatrixComparisonGenerator::~ScMatrixComparisonGenerator()
 {}
 
-void ScMatrixComparisonGenerator::CalculateInputAndWriteToOutput( )
+sal_Int16 ScMatrixComparisonGenerator::GetUndoNameId()
 {
-    OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, STR_CORRELATION_UNDO_NAME));
-    ScDocShell* pDocShell = mViewData->GetDocShell();
-    svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
-    pUndoManager->EnterListAction( aUndo, aUndo );
+    return STR_CORRELATION_UNDO_NAME;
+}
 
+ScRange ScMatrixComparisonGenerator::ApplyOutput(ScDocShell* pDocShell)
+{
     AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument);
     FormulaTemplate aTemplate(mDocument, mAddressDetails);
 
@@ -128,9 +128,7 @@ void ScMatrixComparisonGenerator::CalculateInputAndWriteToOutput( )
 
     lclWriteCorrelationFormulas(output, aTemplate, aRangeList, getTemplate());
 
-    ScRange aOutputRange(output.mMinimumAddress, output.mMaximumAddress);
-    pUndoManager->LeaveListAction();
-    pDocShell->PostPaint(aOutputRange, PAINT_GRID);
+    return ScRange(output.mMinimumAddress, output.mMaximumAddress);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx b/sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx
index d3af93e..04f4245 100644
--- a/sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx
@@ -45,13 +45,13 @@ sal_Bool ScMovingAverageDialog::Close()
     return DoClose( ScMovingAverageDialogWrapper::GetChildWindowId() );
 }
 
-void ScMovingAverageDialog::CalculateInputAndWriteToOutput( )
+sal_Int16 ScMovingAverageDialog::GetUndoNameId()
 {
-    OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, STR_MOVING_AVERAGE_UNDO_NAME));
-    ScDocShell* pDocShell = mViewData->GetDocShell();
-    svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
-    pUndoManager->EnterListAction( aUndo, aUndo );
+    return STR_MOVING_AVERAGE_UNDO_NAME;
+}
 
+ScRange ScMovingAverageDialog::ApplyOutput(ScDocShell* pDocShell)
+{
     AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument);
     FormulaTemplate aTemplate(mDocument, mAddressDetails);
 
@@ -68,10 +68,13 @@ void ScMovingAverageDialog::CalculateInputAndWriteToOutput( )
     {
         output.resetRow();
 
-        // Write column label
-        aTemplate.setTemplate("Column %NUMBER%");
+        // Write label
+        if (mGroupedBy == BY_COLUMN)
+            aTemplate.setTemplate("Column %NUMBER%");
+        else
+            aTemplate.setTemplate("Row %NUMBER%");
         aTemplate.applyNumber("%NUMBER%", pIterator->index() + 1);
-        output.writeString(aTemplate.getTemplate());
+        output.writeBoldString(aTemplate.getTemplate());
         output.nextRow();
 
         DataCellIterator aDataCellIterator = pIterator->iterateCells();
@@ -102,16 +105,13 @@ void ScMovingAverageDialog::CalculateInputAndWriteToOutput( )
             }
             else
             {
-                output.writeString("N/A");
+                output.writeFormula("=#N/A");
             }
             output.nextRow();
         }
         output.nextColumn();
     }
-
-    pUndoManager->LeaveListAction();
-    ScRange aOutputRange(output.mMinimumAddress, output.mMaximumAddress);
-    pDocShell->PostPaint( aOutputRange, PAINT_GRID );
+    return ScRange(output.mMinimumAddress, output.mMaximumAddress);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx b/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx
index 7374965..787f17b 100644
--- a/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx
@@ -22,6 +22,7 @@
 #include "scresid.hxx"
 #include "random.hxx"
 #include "docfunc.hxx"
+#include "strload.hxx"
 
 #include "StatisticsInputOutputDialog.hxx"
 
@@ -222,4 +223,17 @@ IMPL_LINK_NOARG( ScStatisticsInputOutputDialog, GroupByChanged )
     return 0;
 }
 
+void ScStatisticsInputOutputDialog::CalculateInputAndWriteToOutput()
+{
+    OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, GetUndoNameId()));
+    ScDocShell* pDocShell = mViewData->GetDocShell();
+    svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
+    pUndoManager->EnterListAction( aUndo, aUndo );
+
+    ScRange aOutputRange = ApplyOutput(pDocShell);
+
+    pUndoManager->LeaveListAction();
+    pDocShell->PostPaint( aOutputRange, PAINT_GRID );
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
index a98257d..efd4581 100644
--- a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
+++ b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
@@ -273,6 +273,11 @@ ScRange DataRangeByColumnIterator::get()
     );
 }
 
+void DataRangeByColumnIterator::reset()
+{
+    mCol = mInputRange.aStart.Col();
+}
+
 DataCellIterator DataRangeByColumnIterator::iterateCells()
 {
     return DataCellIterator(get(), false);
@@ -304,6 +309,11 @@ ScRange DataRangeByRowIterator::get()
     );
 }
 
+void DataRangeByRowIterator::reset()
+{
+    mRow = mInputRange.aStart.Row();
+}
+
 DataCellIterator DataRangeByRowIterator::iterateCells()
 {
     return DataCellIterator(get(), true);
diff --git a/sc/source/ui/inc/AnalysisOfVarianceDialog.hxx b/sc/source/ui/inc/AnalysisOfVarianceDialog.hxx
index 552c2b9..85ebc38 100644
--- a/sc/source/ui/inc/AnalysisOfVarianceDialog.hxx
+++ b/sc/source/ui/inc/AnalysisOfVarianceDialog.hxx
@@ -36,7 +36,8 @@ public:
     virtual sal_Bool Close();
 
 protected:
-    virtual void CalculateInputAndWriteToOutput();
+    virtual sal_Int16 GetUndoNameId();
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell);
 };
 
 #endif
diff --git a/sc/source/ui/inc/DescriptiveStatisticsDialog.hxx b/sc/source/ui/inc/DescriptiveStatisticsDialog.hxx
index b2003b6..a31180a 100644
--- a/sc/source/ui/inc/DescriptiveStatisticsDialog.hxx
+++ b/sc/source/ui/inc/DescriptiveStatisticsDialog.hxx
@@ -33,7 +33,8 @@ public:
     virtual sal_Bool Close();
 
 protected:
-    virtual void CalculateInputAndWriteToOutput();
+    virtual sal_Int16 GetUndoNameId();
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell);
 };
 
 #endif
diff --git a/sc/source/ui/inc/ExponentialSmoothingDialog.hxx b/sc/source/ui/inc/ExponentialSmoothingDialog.hxx
index 57ae997..3aa2dd5 100644
--- a/sc/source/ui/inc/ExponentialSmoothingDialog.hxx
+++ b/sc/source/ui/inc/ExponentialSmoothingDialog.hxx
@@ -36,7 +36,8 @@ public:
     virtual sal_Bool Close();
 
 protected:
-    virtual void CalculateInputAndWriteToOutput();
+    virtual sal_Int16 GetUndoNameId();
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell);
 };
 
 #endif
diff --git a/sc/source/ui/inc/MatrixComparisonGenerator.hxx b/sc/source/ui/inc/MatrixComparisonGenerator.hxx
index 61edd0f..88c8f17 100644
--- a/sc/source/ui/inc/MatrixComparisonGenerator.hxx
+++ b/sc/source/ui/inc/MatrixComparisonGenerator.hxx
@@ -32,7 +32,8 @@ public:
     virtual ~ScMatrixComparisonGenerator();
 
 protected:
-    virtual void CalculateInputAndWriteToOutput();
+    virtual sal_Int16 GetUndoNameId();
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell);
 
     virtual const OUString& getLabel() = 0;
     virtual const OUString& getTemplate() = 0;
diff --git a/sc/source/ui/inc/MovingAverageDialog.hxx b/sc/source/ui/inc/MovingAverageDialog.hxx
index ee5b2bf..ed41600 100644
--- a/sc/source/ui/inc/MovingAverageDialog.hxx
+++ b/sc/source/ui/inc/MovingAverageDialog.hxx
@@ -36,7 +36,8 @@ public:
     virtual sal_Bool Close();
 
 protected:
-    virtual void CalculateInputAndWriteToOutput();
+    virtual sal_Int16 GetUndoNameId();
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell);
 };
 
 #endif
diff --git a/sc/source/ui/inc/StatisticsInputOutputDialog.hxx b/sc/source/ui/inc/StatisticsInputOutputDialog.hxx
index b4d8344..8a316b4 100644
--- a/sc/source/ui/inc/StatisticsInputOutputDialog.hxx
+++ b/sc/source/ui/inc/StatisticsInputOutputDialog.hxx
@@ -38,7 +38,10 @@ public:
     virtual void        SetActive();
 
 protected:
-    virtual void CalculateInputAndWriteToOutput() = 0;
+    virtual void CalculateInputAndWriteToOutput();
+
+    virtual ScRange ApplyOutput(ScDocShell* pDocShell) = 0;
+    virtual sal_Int16 GetUndoNameId() = 0;
 
     // Widgets
     FixedText*          mpInputRangeLabel;
diff --git a/sc/source/ui/inc/TableFillingAndNavigationTools.hxx b/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
index f3d2f9b..9a62b7e 100644
--- a/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
+++ b/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
@@ -108,6 +108,7 @@ public:
     virtual bool hasNext() = 0;
     virtual ScRange get() = 0;
     virtual void next() = 0;
+    virtual void reset() = 0;
     virtual sal_Int32 index();
 
     virtual DataCellIterator iterateCells() = 0;
@@ -124,6 +125,7 @@ public:
     virtual bool hasNext();
     virtual void next();
     virtual ScRange get();
+    virtual void reset();
     virtual DataCellIterator iterateCells();
 };
 
@@ -138,11 +140,10 @@ public:
     virtual bool hasNext();
     virtual void next();
     virtual ScRange get();
+    virtual void reset();
     virtual DataCellIterator iterateCells();
 };
 
-
-
 #endif
 
 
commit a025cd4b00a2f6408c5bfbb932d8cee35a62b66a
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Sun Nov 10 17:06:47 2013 +0100

    ui permissions
    
    Change-Id: I56e81590327881328daf5f80e6330ba78cd8b900

diff --git a/sc/uiconfig/scalc/ui/analysisofvariancedialog.ui b/sc/uiconfig/scalc/ui/analysisofvariancedialog.ui
old mode 100755
new mode 100644
diff --git a/sc/uiconfig/scalc/ui/correlationdialog.ui b/sc/uiconfig/scalc/ui/correlationdialog.ui
old mode 100755
new mode 100644
diff --git a/sc/uiconfig/scalc/ui/covariancedialog.ui b/sc/uiconfig/scalc/ui/covariancedialog.ui
old mode 100755
new mode 100644
diff --git a/sc/uiconfig/scalc/ui/descriptivestatisticsdialog.ui b/sc/uiconfig/scalc/ui/descriptivestatisticsdialog.ui
old mode 100755
new mode 100644
diff --git a/sc/uiconfig/scalc/ui/exponentialsmoothingdialog.ui b/sc/uiconfig/scalc/ui/exponentialsmoothingdialog.ui
old mode 100755
new mode 100644
diff --git a/sc/uiconfig/scalc/ui/movingaveragedialog.ui b/sc/uiconfig/scalc/ui/movingaveragedialog.ui
old mode 100755
new mode 100644
commit 515a5024377f5c93e962c65cfd987bf5d52d135c
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Sun Nov 10 16:26:34 2013 +0100

    Add statistics dialog for calculation of moving average.
    
    Change-Id: Iaa481a2d8aff271e8a8350b707e1f444f8d36167

diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index da9b259..9a32ed6 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
@@ -691,6 +691,14 @@
           <value>1</value>
         </prop>
       </node>
+      <node oor:name=".uno:MovingAverageDialog" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">~Moving Average...</value>
+        </prop>
+        <prop oor:name="Properties" oor:type="xs:int">
+          <value>1</value>
+        </prop>
+      </node>
       <node oor:name=".uno:EditHeaderAndFooter" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
           <value xml:lang="en-US">~Headers & Footers...</value>
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index f763eda..f65cf26 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -477,6 +477,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
     sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog \
     sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog \
     sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator \
+    sc/source/ui/StatisticsDialogs/MovingAverageDialog \
     sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog \
     sc/source/ui/StatisticsDialogs/SamplingDialog \
     sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog \
diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk
index 61442aa..2aa1ff8 100644
--- a/sc/UIConfig_scalc.mk
+++ b/sc/UIConfig_scalc.mk
@@ -136,6 +136,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\
 	sc/uiconfig/scalc/ui/ungroupdialog \
 	sc/uiconfig/scalc/ui/validationhelptabpage \
 	sc/uiconfig/scalc/ui/movecopysheet \
+	sc/uiconfig/scalc/ui/movingaveragedialog \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index 47c73ae..d901083 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -262,6 +262,7 @@
 #define SID_CORRELATION_DIALOG              (SC_MESSAGE_START + 74)
 #define SID_COVARIANCE_DIALOG               (SC_MESSAGE_START + 75)
 #define SID_EXPONENTIAL_SMOOTHING_DIALOG    (SC_MESSAGE_START + 76)
+#define SID_MOVING_AVERAGE_DIALOG           (SC_MESSAGE_START + 77)
 
 // functions
 
diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi
index 46d9dff..6fe3b24 100644
--- a/sc/sdi/cellsh.sdi
+++ b/sc/sdi/cellsh.sdi
@@ -154,6 +154,7 @@ interface CellSelection
     SID_CORRELATION_DIALOG              [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
     SID_COVARIANCE_DIALOG               [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
     SID_EXPONENTIAL_SMOOTHING_DIALOG    [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
+    SID_MOVING_AVERAGE_DIALOG           [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
     SID_MARKDATAAREA    [ ExecMethod = ExecuteMove; StateMethod = GetStateCursor; ]
     SID_MARKARRAYFORMULA [ ExecMethod = ExecuteMove; StateMethod = GetStateCursor; ]
     SID_SETINPUTMODE    [ ExecMethod = ExecuteMove; StateMethod = GetStateCursor; ]
diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index d5260bf..e892023 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -3110,6 +3110,30 @@ SfxVoidItem ExponentialSmoothingDialog SID_EXPONENTIAL_SMOOTHING_DIALOG
     GroupId = GID_OPTIONS;
 ]
 
+SfxVoidItem MovingAverageDialog SID_MOVING_AVERAGE_DIALOG
+()
+[
+    /* flags: */
+    AutoUpdate = FALSE,
+    Cachable = Cachable,
+    FastCall = FALSE,
+    HasCoreId = FALSE,
+    HasDialog = TRUE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Synchron;
+
+    /* config: */
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    StatusBarConfig = FALSE,
+    ToolBoxConfig = TRUE,
+    GroupId = GID_OPTIONS;
+]
+
 //--------------------------------------------------------------------------
 SfxVoidItem SolverDialog SID_OPENDLG_OPTSOLVER
 ()
diff --git a/sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx b/sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx
new file mode 100644
index 0000000..d3af93e
--- /dev/null
+++ b/sc/source/ui/StatisticsDialogs/MovingAverageDialog.cxx
@@ -0,0 +1,117 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <sfx2/dispatch.hxx>
+#include <svl/zforlist.hxx>
+#include <svl/undo.hxx>
+
+#include "formulacell.hxx"
+#include "rangelst.hxx"
+#include "scitems.hxx"
+#include "docsh.hxx"
+#include "document.hxx"
+#include "uiitems.hxx"
+#include "reffact.hxx"
+#include "strload.hxx"
+#include "random.hxx"
+#include "docfunc.hxx"
+#include "StatisticsDialogs.hrc"
+#include "TableFillingAndNavigationTools.hxx"
+
+#include "MovingAverageDialog.hxx"
+
+ScMovingAverageDialog::ScMovingAverageDialog(
+                    SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
+                    Window* pParent, ScViewData* pViewData ) :
+    ScStatisticsInputOutputDialog(
+            pSfxBindings, pChildWindow, pParent, pViewData,
+            "MovingAverageDialog", "modules/scalc/ui/movingaveragedialog.ui" )
+{
+    get(mpIntervalSpin, "interval-spin");
+}
+
+ScMovingAverageDialog::~ScMovingAverageDialog()
+{}
+
+sal_Bool ScMovingAverageDialog::Close()
+{
+    return DoClose( ScMovingAverageDialogWrapper::GetChildWindowId() );
+}
+
+void ScMovingAverageDialog::CalculateInputAndWriteToOutput( )
+{
+    OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, STR_MOVING_AVERAGE_UNDO_NAME));
+    ScDocShell* pDocShell = mViewData->GetDocShell();
+    svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
+    pUndoManager->EnterListAction( aUndo, aUndo );
+
+    AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument);
+    FormulaTemplate aTemplate(mDocument, mAddressDetails);
+
+    boost::scoped_ptr<DataRangeIterator> pIterator;
+    if (mGroupedBy == BY_COLUMN)
+        pIterator.reset(new DataRangeByColumnIterator(mInputRange));
+    else
+        pIterator.reset(new DataRangeByRowIterator(mInputRange));
+
+    sal_Int32 aIntervalSize = mpIntervalSpin->GetValue();
+    bool aCentral = true;
+
+    for( ; pIterator->hasNext(); pIterator->next() )
+    {
+        output.resetRow();
+
+        // Write column label
+        aTemplate.setTemplate("Column %NUMBER%");
+        aTemplate.applyNumber("%NUMBER%", pIterator->index() + 1);
+        output.writeString(aTemplate.getTemplate());
+        output.nextRow();
+
+        DataCellIterator aDataCellIterator = pIterator->iterateCells();
+
+        for (; aDataCellIterator.hasNext(); aDataCellIterator.next())
+        {
+            ScAddress aIntervalStart;
+            ScAddress aIntervalEnd;
+
+            if (aCentral)
+            {
+                sal_Int32 aHalf = aIntervalSize / 2;
+                sal_Int32 aHalfRemainder = aIntervalSize % 2;
+                aIntervalStart = aDataCellIterator.getRelative(-aHalf);
+                aIntervalEnd = aDataCellIterator.getRelative(aHalf - 1 + aHalfRemainder);
+            }
+            else
+            {
+                aIntervalStart = aDataCellIterator.getRelative(-aIntervalSize);
+                aIntervalEnd = aDataCellIterator.getRelative(0);
+            }
+
+            if(aIntervalStart.IsValid() && aIntervalEnd.IsValid())
+            {
+                aTemplate.setTemplate("=AVERAGE(%RANGE%)");
+                aTemplate.applyRange("%RANGE%", ScRange(aIntervalStart, aIntervalEnd));
+                output.writeFormula(aTemplate.getTemplate());
+            }
+            else
+            {
+                output.writeString("N/A");
+            }
+            output.nextRow();
+        }
+        output.nextColumn();
+    }
+
+    pUndoManager->LeaveListAction();
+    ScRange aOutputRange(output.mMinimumAddress, output.mMaximumAddress);
+    pDocShell->PostPaint( aOutputRange, PAINT_GRID );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/StatisticsDialogs.hrc b/sc/source/ui/StatisticsDialogs/StatisticsDialogs.hrc
index 64cbfe5..8749ab2 100644
--- a/sc/source/ui/StatisticsDialogs/StatisticsDialogs.hrc
+++ b/sc/source/ui/StatisticsDialogs/StatisticsDialogs.hrc
@@ -52,5 +52,6 @@
 #define STR_CORRELATION_UNDO_NAME                   36
 #define STR_COVARIANCE_UNDO_NAME                    37
 #define STR_EXPONENTIAL_SMOOTHING_UNDO_NAME         38
+#define STR_MOVING_AVERAGE_UNDO_NAME                39
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/StatisticsDialogs.src b/sc/source/ui/StatisticsDialogs/StatisticsDialogs.src
index cf39edec8..493970f 100644
--- a/sc/source/ui/StatisticsDialogs/StatisticsDialogs.src
+++ b/sc/source/ui/StatisticsDialogs/StatisticsDialogs.src
@@ -13,7 +13,14 @@
 Resource RID_STATISTICS_DLGS
 {
 
-    /* AnalysisOfVarianceDialog */
+    /* MovingAverageDialog */
+
+    String STR_MOVING_AVERAGE_UNDO_NAME
+    {
+        Text [ en-US ] = "Moving Average";
+    };
+
+    /* ExponentialSmoothingDialog */
 
     String STR_EXPONENTIAL_SMOOTHING_UNDO_NAME
     {
diff --git a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
index bf5080b..a98257d 100644
--- a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
+++ b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
@@ -8,6 +8,14 @@
  *
  */
 
+#include <boost/scoped_ptr.hpp>
+
+#include <editeng/editobj.hxx>
+#include <editeng/wghtitem.hxx>
+#include <editeng/eeitem.hxx>
+
+#include "editutil.hxx"
+
 #include "TableFillingAndNavigationTools.hxx"
 
 FormulaTemplate::FormulaTemplate(ScDocument* aDocument, ScAddress::Details aAddressDetails) :
@@ -54,6 +62,11 @@ void FormulaTemplate::applyString(OUString aVariable, OUString aValue)
     mTemplate = mTemplate.replaceAll(aVariable, aValue);
 }
 
+void FormulaTemplate::applyNumber(OUString aVariable, sal_Int32 aValue)
+{
+    mTemplate = mTemplate.replaceAll(aVariable, OUString::number(aValue));
+}
+
 AddressWalker::AddressWalker(ScAddress aInitialAddress, bool aTrackRange) :
     mCurrentAddress(aInitialAddress),
     mMinimumAddress(aInitialAddress),
@@ -137,7 +150,19 @@ void AddressWalkerWriter::writeString(OUString aString)
 
 void AddressWalkerWriter::writeString(const char* aCharArray)
 {
-    mpDocShell->GetDocFunc().SetStringCell(mCurrentAddress, OUString::createFromAscii(aCharArray), true);
+    writeString(OUString::createFromAscii(aCharArray));
+}
+
+void AddressWalkerWriter::writeBoldString(OUString aString)
+{
+    ScFieldEditEngine& rEngine = mpDocument->GetEditEngine();
+    rEngine.SetText(aString);
+    SfxItemSet aItemSet = rEngine.GetEmptyItemSet();
+    SvxWeightItem aWeight(WEIGHT_BOLD, EE_CHAR_WEIGHT);
+    aItemSet.Put(aWeight);
+    rEngine.QuickSetAttribs(aItemSet, ESelection(0, 0, 0, aString.getLength()) );
+    boost::scoped_ptr<EditTextObject> pEditText(rEngine.CreateTextObject());
+    mpDocShell->GetDocFunc().SetEditCell(mCurrentAddress, *pEditText, true);
 }
 
 void AddressWalkerWriter::writeValue(double aValue)
@@ -178,18 +203,33 @@ void DataCellIterator::next()
 
 ScAddress DataCellIterator::get()
 {
-    if(mByColumn)
-        return ScAddress(mCol, mInputRange.aStart.Row(), mInputRange.aStart.Tab());
-    else
-        return ScAddress(mInputRange.aStart.Col(), mRow, mInputRange.aStart.Tab());
+    return getRelative(0);
 }
 
 ScAddress DataCellIterator::getRelative(int aDelta)
 {
     if(mByColumn)
-        return ScAddress(mCol + aDelta, mInputRange.aStart.Row(), mInputRange.aStart.Tab());
+    {
+        SCCOL aNewColumn = mCol + aDelta;
+        if(aNewColumn < mInputRange.aStart.Col() || aNewColumn > mInputRange.aEnd.Col())
+        {
+            ScAddress aResult;
+            aResult.SetInvalid();
+            return aResult;
+        }
+        return ScAddress(aNewColumn, mInputRange.aStart.Row(), mInputRange.aStart.Tab());
+    }
     else
-        return ScAddress(mInputRange.aStart.Col(), mRow + aDelta, mInputRange.aStart.Tab());
+    {
+        SCROW aNewRow = mRow + aDelta;
+        if(aNewRow < mInputRange.aStart.Row() || aNewRow > mInputRange.aEnd.Row())
+        {
+            ScAddress aResult;
+            aResult.SetInvalid();
+            return aResult;
+        }
+        return ScAddress(mInputRange.aStart.Col(), aNewRow, mInputRange.aStart.Tab());
+    }
 }
 
 // DataRangeIterator
diff --git a/sc/source/ui/app/scdll.cxx b/sc/source/ui/app/scdll.cxx
index c21fc3b..84f5823 100644
--- a/sc/source/ui/app/scdll.cxx
+++ b/sc/source/ui/app/scdll.cxx
@@ -250,8 +250,7 @@ void ScDLL::Init()
 
     // Hack: Eingabezeile mit 42 registrieren, damit sie im PlugIn immer sichtbar ist
     ScInputWindowWrapper        ::RegisterChildWindow(42, pMod, SFX_CHILDWIN_TASK|SFX_CHILDWIN_FORCEDOCK);
-    ScNavigatorDialogWrapper    ::RegisterChildWindowContext(
-            sal::static_int_cast<sal_uInt16>(ScTabViewShell::GetInterfaceId()), pMod);
+    ScNavigatorDialogWrapper    ::RegisterChildWindowContext(static_cast<sal_uInt16>(ScTabViewShell::GetInterfaceId()), pMod);
     ScSolverDlgWrapper          ::RegisterChildWindow(false, pMod);
     ScOptSolverDlgWrapper       ::RegisterChildWindow(false, pMod);
     ScXMLSourceDlgWrapper       ::RegisterChildWindow(false, pMod);
@@ -274,6 +273,7 @@ void ScDLL::Init()
     ScCorrelationDialogWrapper          ::RegisterChildWindow(false, pMod);
     ScCovarianceDialogWrapper           ::RegisterChildWindow(false, pMod);
     ScExponentialSmoothingDialogWrapper ::RegisterChildWindow(false, pMod);
+    ScMovingAverageDialogWrapper        ::RegisterChildWindow(false, pMod);
 
     // First docking Window for Calc
     ScFunctionChildWindow       ::RegisterChildWindow(false, pMod);
diff --git a/sc/source/ui/inc/MovingAverageDialog.hxx b/sc/source/ui/inc/MovingAverageDialog.hxx
new file mode 100644
index 0000000..ee5b2bf
--- /dev/null
+++ b/sc/source/ui/inc/MovingAverageDialog.hxx
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef MOVING_AVERAGE_DIALOG_HXX
+#define MOVING_AVERAGE_DIALOG_HXX
+
+#include "global.hxx"
+#include "address.hxx"
+#include "anyrefdg.hxx"
+
+#include <vcl/fixed.hxx>
+#include <vcl/group.hxx>
+#include <vcl/lstbox.hxx>
+
+#include "StatisticsInputOutputDialog.hxx"
+
+class ScMovingAverageDialog : public ScStatisticsInputOutputDialog
+{
+private:
+    NumericField* mpIntervalSpin;
+
+public:
+    ScMovingAverageDialog(
+        SfxBindings* pB, SfxChildWindow* pCW,
+        Window* pParent, ScViewData* pViewData );
+
+    virtual ~ScMovingAverageDialog();
+
+    virtual sal_Bool Close();
+
+protected:
+    virtual void CalculateInputAndWriteToOutput();
+};
+
+#endif
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/TableFillingAndNavigationTools.hxx b/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
index 6354df9..f3d2f9b 100644
--- a/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
+++ b/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
@@ -37,6 +37,7 @@ public:
     void        applyRangeList(OUString aVariable, ScRangeList aRangeList);
     void        applyAddress(OUString aVariable, ScAddress aAddress);
     void        applyString(OUString aVariable, OUString aValue);
+    void        applyNumber(OUString aVariable, sal_Int32 aValue);
 };
 
 class AddressWalker
@@ -72,6 +73,7 @@ public:
     void writeFormula(OUString aFormula);
     void writeString(OUString aString);
     void writeString(const char* aCharArray);
+    void writeBoldString(OUString aString);
     void writeValue(double aValue);
 };
 
diff --git a/sc/source/ui/inc/reffact.hxx b/sc/source/ui/inc/reffact.hxx
index 5785192..da3668c 100644
--- a/sc/source/ui/inc/reffact.hxx
+++ b/sc/source/ui/inc/reffact.hxx
@@ -102,6 +102,14 @@ private:
     ScExponentialSmoothingDialogWrapper() SAL_DELETED_FUNCTION;
 };
 
+class ScMovingAverageDialogWrapper :
+    public ChildWindowWrapper<SID_MOVING_AVERAGE_DIALOG>
+{
+private:
+    ScMovingAverageDialogWrapper() SAL_DELETED_FUNCTION;
+};
+
+
 class ScAcceptChgDlgWrapper: public SfxChildWindow
 {
     public:
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index f2d3eb1..5b3c6b9 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -965,6 +965,15 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
             }
             break;
+        case SID_MOVING_AVERAGE_DIALOG:
+            {
+                sal_uInt16 nId  = ScMovingAverageDialogWrapper::GetChildWindowId();
+                SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
+                SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
+
+                pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
+            }
+            break;
 
         //
         //  disposal (Outlines)
diff --git a/sc/source/ui/view/tabvwsh.cxx b/sc/source/ui/view/tabvwsh.cxx
index 63925b1..0298764 100644
--- a/sc/source/ui/view/tabvwsh.cxx
+++ b/sc/source/ui/view/tabvwsh.cxx
@@ -88,6 +88,7 @@ SFX_IMPL_INTERFACE(ScTabViewShell,SfxViewShell,ScResId(SCSTR_TABVIEWSHELL))
     SFX_CHILDWINDOW_REGISTRATION(ScCorrelationDialogWrapper::GetChildWindowId());
     SFX_CHILDWINDOW_REGISTRATION(ScCovarianceDialogWrapper::GetChildWindowId());
     SFX_CHILDWINDOW_REGISTRATION(ScExponentialSmoothingDialogWrapper::GetChildWindowId());
+    SFX_CHILDWINDOW_REGISTRATION(ScMovingAverageDialogWrapper::GetChildWindowId());
 
 }
 
diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx
index 24aab3d..a91377c 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -68,6 +68,7 @@
 #include "CorrelationDialog.hxx"
 #include "CovarianceDialog.hxx"
 #include "ExponentialSmoothingDialog.hxx"
+#include "MovingAverageDialog.hxx"
 
 #include <config_orcus.h>
 
@@ -363,6 +364,12 @@ SfxModelessDialog* ScTabViewShell::CreateRefDialog(
         }
         break;
 
+        case SID_MOVING_AVERAGE_DIALOG:
+        {
+            pResult = new ScMovingAverageDialog( pB, pCW, pParent, GetViewData() );
+        }
+        break;
+
         case SID_OPENDLG_OPTSOLVER:
         {
             ScViewData* pViewData = GetViewData();
diff --git a/sc/uiconfig/scalc/menubar/menubar.xml b/sc/uiconfig/scalc/menubar/menubar.xml
index acd835a..04b059d 100644
--- a/sc/uiconfig/scalc/menubar/menubar.xml
+++ b/sc/uiconfig/scalc/menubar/menubar.xml
@@ -489,6 +489,7 @@
                     <menu:menuitem menu:id=".uno:CorrelationDialog"/>
                     <menu:menuitem menu:id=".uno:CovarianceDialog"/>
                     <menu:menuitem menu:id=".uno:ExponentialSmoothingDialog"/>
+                    <menu:menuitem menu:id=".uno:MovingAverageDialog"/>
                 </menu:menupopup>
             </menu:menu>
         </menu:menupopup>
diff --git a/sc/uiconfig/scalc/ui/movingaveragedialog.ui b/sc/uiconfig/scalc/ui/movingaveragedialog.ui
new file mode 100755
index 0000000..9e1f667
--- /dev/null
+++ b/sc/uiconfig/scalc/ui/movingaveragedialog.ui
@@ -0,0 +1,342 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.0 on Sun Nov 10 13:10:53 2013 -->
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <!-- interface-requires LibreOffice 1.0 -->
+  <object class="GtkAdjustment" id="interval-adjustment">
+    <property name="lower">2</property>
+    <property name="upper">10000</property>
+    <property name="value">2</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">1</property>
+  </object>
+  <object class="GtkDialog" id="MovingAverageDialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Moving Average</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="apply">
+                <property name="label">gtk-apply</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="ok">
+                <property name="label">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="close">
+                <property name="label">gtk-close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="row_spacing">6</property>
+            <property name="column_spacing">12</property>
+            <child>
+              <object class="GtkLabel" id="input-range-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Input Range</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">input-range-edit</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="foruilo-RefEdit" id="input-range-edit">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="valign">center</property>
+                <property name="hexpand">True</property>
+                <property name="invisible_char">•</property>
+                <property name="width_chars">30</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="foruilo-RefButton" id="input-range-button">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="receives_default">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="output-range-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Output Range</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">output-range-edit</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="foruilo-RefEdit" id="output-range-edit">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="valign">center</property>
+                <property name="hexpand">True</property>
+                <property name="invisible_char">•</property>
+                <property name="width_chars">30</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="foruilo-RefButton" id="output-range-button">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="receives_default">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkFrame" id="frame2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="top_padding">6</property>
+                    <property name="bottom_padding">6</property>
+                    <property name="left_padding">12</property>
+                    <property name="right_padding">12</property>
+                    <child>
+                      <object class="GtkGrid" id="grid2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="row_spacing">6</property>
+                        <property name="column_spacing">12</property>
+                        <child>
+                          <object class="GtkRadioButton" id="groupedby-columns-radio">
+                            <property name="label" translatable="yes">Columns</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="xalign">0</property>
+                            <property name="active">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">0</property>
+                            <property name="top_attach">0</property>
+                            <property name="width">1</property>
+                            <property name="height">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkRadioButton" id="groupedby-rows-radio">
+                            <property name="label" translatable="yes">Rows</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="xalign">0</property>
+                            <property name="draw_indicator">True</property>
+                            <property name="group">groupedby-columns-radio</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="top_attach">0</property>
+                            <property name="width">1</property>
+                            <property name="height">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Grouped by</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+                <property name="width">3</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkFrame" id="frame1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="top_padding">6</property>
+                    <property name="bottom_padding">6</property>
+                    <property name="left_padding">12</property>
+                    <property name="right_padding">12</property>
+                    <child>
+                      <object class="GtkGrid" id="grid3">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="row_spacing">6</property>
+                        <property name="column_spacing">12</property>
+                        <child>
+                          <object class="GtkLabel" id="interval-label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">Interval</property>
+                            <property name="use_underline">True</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">0</property>
+                            <property name="top_attach">0</property>
+                            <property name="width">1</property>
+                            <property name="height">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkSpinButton" id="interval-spin">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="invisible_char">•</property>
+                            <property name="adjustment">interval-adjustment</property>
+                            <property name="value">2</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="top_attach">0</property>
+                            <property name="width">1</property>
+                            <property name="height">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Parameters</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">3</property>
+                <property name="width">3</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">apply</action-widget>
+      <action-widget response="0">ok</action-widget>
+      <action-widget response="0">close</action-widget>
+    </action-widgets>
+  </object>
+</interface>
commit f4569ff5ee721683c6ba09b75fe0ce14e3203d3a
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Thu Nov 7 23:06:26 2013 +0100

    Iterators for data ranges and data cells.
    
    This is needed to make data and iteration independent from the
    data orientation (either columns or rows).
    
    Change-Id: I03d0fca939ba9b051832668d229e4961c097add6

diff --git a/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
index 7709c5d..4257165 100644
--- a/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
@@ -45,9 +45,10 @@ static const char* lclAnovaLabels[] =
     "Source of Variation", "SS", "df", "MS", "F", "P-value", "F critical", NULL
 };
 
+static const OUString strWildcardRange("%RANGE%");
 static const OUString strWildcardNumber("%NUMBER%");
 static const OUString strColumnLabelTemplate("Column %NUMBER%");
-static const OUString strWildcardRange("%RANGE%");
+static const OUString strRowLabelTemplate("Row %NUMBER%");
 
 OUString lclCreateMultiParameterFormula(
             ScRangeList&        aRangeList, const OUString& aFormulaTemplate,
@@ -94,14 +95,9 @@ void ScAnalysisOfVarianceDialog::CalculateInputAndWriteToOutput( )
     svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
     pUndoManager->EnterListAction( aUndo, aUndo );
 
-    ScAddress aStart = mInputRange.aStart;
-    ScAddress aEnd   = mInputRange.aEnd;
-
     AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument);
     FormulaTemplate aTemplate(mDocument, mAddressDetails);
 
-    SCROW inTab = aStart.Tab();
-
     // Write labels
     for(sal_Int32 i = 0; lclBasicStatisticsLabels[i] != NULL; i++)
     {
@@ -112,19 +108,27 @@ void ScAnalysisOfVarianceDialog::CalculateInputAndWriteToOutput( )
 
     ScRangeList aRangeList;
 
+    boost::scoped_ptr<DataRangeIterator> pIterator;
+    if (mGroupedBy == BY_COLUMN)
+        pIterator.reset(new DataRangeByColumnIterator(mInputRange));
+    else
+        pIterator.reset(new DataRangeByRowIterator(mInputRange));
+
     // Write statistic formulas for columns
-    for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
+    for( ; pIterator->hasNext(); pIterator->next() )
     {
         output.resetColumn();
-        aTemplate.setTemplate(strColumnLabelTemplate);
-        aTemplate.applyString(strWildcardNumber, OUString::number(inCol - aStart.Col() + 1));
+
+        if (mGroupedBy == BY_COLUMN)
+            aTemplate.setTemplate(strColumnLabelTemplate);
+        else
+            aTemplate.setTemplate(strRowLabelTemplate);
+
+        aTemplate.applyString(strWildcardNumber, OUString::number(pIterator->index() + 1));
         pDocShell->GetDocFunc().SetStringCell(output.current(), aTemplate.getTemplate(), true);
         output.nextColumn();
 
-        ScRange aColumnRange(
-            ScAddress(inCol, aStart.Row(), inTab),
-            ScAddress(inCol, aEnd.Row(), inTab)
-        );
+        ScRange aColumnRange = pIterator->get();
 
         aRangeList.Append(aColumnRange);
 
diff --git a/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx b/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
index 19b4788..d9a18a0 100644
--- a/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
@@ -12,6 +12,7 @@
 #include <svl/zforlist.hxx>
 #include <svl/undo.hxx>
 #include <boost/random.hpp>
+#include <boost/scoped_ptr.hpp>
 
 #include "formulacell.hxx"
 #include "rangelst.hxx"
@@ -86,8 +87,6 @@ void ScDescriptiveStatisticsDialog::CalculateInputAndWriteToOutput( )
     AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument);
     FormulaTemplate aTemplate(mDocument, mAddressDetails);
 
-    SCROW inTab = mInputRange.aStart.Tab();
-
     for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
     {
         OUString aLabel(SC_STRLOAD(RID_STATISTICS_DLGS, lclCalcDefinitions[i].aCalculationNameId));
@@ -96,19 +95,20 @@ void ScDescriptiveStatisticsDialog::CalculateInputAndWriteToOutput( )
     }
     aOutput.nextColumn();
 
-    for (SCCOL inCol = mInputRange.aStart.Col(); inCol <= mInputRange.aEnd.Col(); inCol++)
+    boost::scoped_ptr<DataRangeIterator> pIterator;
+    if (mGroupedBy == BY_COLUMN)
+        pIterator.reset(new DataRangeByColumnIterator(mInputRange));
+    else
+        pIterator.reset(new DataRangeByRowIterator(mInputRange));
+
+    for( ; pIterator->hasNext(); pIterator->next() )
     {
         aOutput.resetRow();
 
-        ScRange aColumnRange(
-            ScAddress(inCol, mInputRange.aStart.Row(), inTab),
-            ScAddress(inCol, mInputRange.aEnd.Row(), inTab)
-        );
-
         for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
         {
             aTemplate.setTemplate(lclCalcDefinitions[i].aFormula);
-            aTemplate.applyRange(strWildcardRange, aColumnRange);
+            aTemplate.applyRange(strWildcardRange, pIterator->get());
             aOutput.writeFormula(aTemplate.getTemplate());
             aOutput.nextRow();
         }
diff --git a/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx b/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
index 9afeb48..34cfcf4 100644
--- a/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
@@ -52,14 +52,9 @@ void ScExponentialSmoothingDialog::CalculateInputAndWriteToOutput( )
     svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
     pUndoManager->EnterListAction( aUndo, aUndo );
 
-    ScAddress aStart = mInputRange.aStart;
-    ScAddress aEnd   = mInputRange.aEnd;
-
     AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument);
     FormulaTemplate aTemplate(mDocument, mAddressDetails);
 
-    SCROW inTab = aStart.Tab();
-
     // Smoothing factor
     double aSmoothingFactor = mpSmoothingFactor->GetValue() / 100.0;
 
@@ -70,37 +65,39 @@ void ScExponentialSmoothingDialog::CalculateInputAndWriteToOutput( )
     // Exponential Smoothing
     output.push();
 
-    for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
+    boost::scoped_ptr<DataRangeIterator> pIterator;
+    if (mGroupedBy == BY_COLUMN)
+        pIterator.reset(new DataRangeByColumnIterator(mInputRange));
+    else
+        pIterator.reset(new DataRangeByRowIterator(mInputRange));
+
+    for( ; pIterator->hasNext(); pIterator->next() )
     {
         output.resetRow();
 
-        SCROW inRow = aStart.Row();
+        ScRange aCurrentRange = pIterator->get();
 
         if (false)
         {
-            ScRange aColumnRange (
-                    ScAddress(inCol, mInputRange.aStart.Row(), inTab),
-                    ScAddress(inCol, mInputRange.aEnd.Row(), inTab));
-
             aTemplate.setTemplate("=AVERAGE(%RANGE%)");
-            aTemplate.applyRange("%RANGE%", aColumnRange);
+            aTemplate.applyRange("%RANGE%", aCurrentRange);
             output.writeFormula(aTemplate.getTemplate());
         }
         else
         {
-            ScAddress aFirstValueAddress(inCol, mInputRange.aStart.Row(), inTab);
-
             aTemplate.setTemplate("=%VAR%");
-            aTemplate.applyAddress("%VAR%", aFirstValueAddress);
+            aTemplate.applyAddress("%VAR%", aCurrentRange.aStart);
             output.writeFormula(aTemplate.getTemplate());
         }
 
         output.nextRow();
 
-        for (inRow = aStart.Row() + 1; inRow <= aEnd.Row(); inRow++)
+        DataCellIterator aDataCellIterator = pIterator->iterateCells();
+
+        for (; aDataCellIterator.hasNext(); aDataCellIterator.next())
         {
             aTemplate.setTemplate("=%VALUE% * %PREVIOUS_INPUT% + (1 - %VALUE%) * %PREVIOUS_OUTPUT%");
-            aTemplate.applyAddress("%PREVIOUS_INPUT%",  ScAddress(inCol, inRow - 1, inTab));
+            aTemplate.applyAddress("%PREVIOUS_INPUT%",  aDataCellIterator.get());
             aTemplate.applyAddress("%PREVIOUS_OUTPUT%", output.current(0, -1));
             aTemplate.applyAddress("%VALUE%",           aSmoothingFactorAddress);
 
diff --git a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
index 05f4397..bf5080b 100644
--- a/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
+++ b/sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools.cxx
@@ -145,4 +145,128 @@ void AddressWalkerWriter::writeValue(double aValue)
     mpDocShell->GetDocFunc().SetValueCell(mCurrentAddress, aValue, true);
 }
 
+// DataCellIterator
+
+DataCellIterator::DataCellIterator(ScRange aInputRange, bool aByColumn) :
+    mInputRange(aInputRange),
+    mByColumn(aByColumn)
+{
+    if(aByColumn)
+        mCol = aInputRange.aStart.Col();
+    else
+        mRow = aInputRange.aStart.Row();
+}
+
+DataCellIterator::~DataCellIterator()
+{}
+
+bool DataCellIterator::hasNext()
+{
+    if(mByColumn)
+        return mCol <= mInputRange.aEnd.Col();
+    else
+        return mRow <= mInputRange.aEnd.Row();
+}
+
+void DataCellIterator::next()
+{
+    if(mByColumn)
+        mCol++;
+    else
+        mRow++;
+}
+
+ScAddress DataCellIterator::get()
+{
+    if(mByColumn)
+        return ScAddress(mCol, mInputRange.aStart.Row(), mInputRange.aStart.Tab());
+    else
+        return ScAddress(mInputRange.aStart.Col(), mRow, mInputRange.aStart.Tab());
+}
+
+ScAddress DataCellIterator::getRelative(int aDelta)
+{
+    if(mByColumn)
+        return ScAddress(mCol + aDelta, mInputRange.aStart.Row(), mInputRange.aStart.Tab());
+    else
+        return ScAddress(mInputRange.aStart.Col(), mRow + aDelta, mInputRange.aStart.Tab());
+}
+
+// DataRangeIterator
+
+DataRangeIterator::DataRangeIterator(ScRange aInputRange) :
+    mInputRange(aInputRange),
+    mIndex(0)
+{}
+
+DataRangeIterator::~DataRangeIterator()
+{}
+
+sal_Int32 DataRangeIterator::index()
+{
+    return mIndex;
+}
+
+// DataRangeByColumnIterator
+
+DataRangeByColumnIterator::DataRangeByColumnIterator(ScRange aInputRange) :
+    DataRangeIterator(aInputRange),
+    mCol(aInputRange.aStart.Col())
+{}
+
+bool DataRangeByColumnIterator::hasNext()
+{
+    return mCol <= mInputRange.aEnd.Col();
+}
+
+void DataRangeByColumnIterator::next()
+{
+    mCol++;
+    mIndex++;
+}
+
+ScRange DataRangeByColumnIterator::get()
+{
+    return ScRange(
+        ScAddress(mCol, mInputRange.aStart.Row(), mInputRange.aStart.Tab()),
+        ScAddress(mCol, mInputRange.aEnd.Row(),   mInputRange.aEnd.Tab())
+    );
+}
+
+DataCellIterator DataRangeByColumnIterator::iterateCells()
+{
+    return DataCellIterator(get(), false);
+}
+
+// DataRangeByRowIterator
+
+DataRangeByRowIterator::DataRangeByRowIterator(ScRange aInputRange) :
+    DataRangeIterator(aInputRange),
+    mRow(aInputRange.aStart.Row())
+{}
+
+bool DataRangeByRowIterator::hasNext()
+{
+    return mRow <= mInputRange.aEnd.Row();
+}
+
+void DataRangeByRowIterator::next()
+{
+    mRow++;
+    mIndex++;
+}
+
+ScRange DataRangeByRowIterator::get()
+{
+    return ScRange(
+        ScAddress(mInputRange.aStart.Col(), mRow, mInputRange.aStart.Tab()),
+        ScAddress(mInputRange.aEnd.Col(),   mRow, mInputRange.aEnd.Tab())
+    );
+}
+
+DataCellIterator DataRangeByRowIterator::iterateCells()
+{
+    return DataCellIterator(get(), true);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/TableFillingAndNavigationTools.hxx b/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
index ff95a58..6354df9 100644
--- a/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
+++ b/sc/source/ui/inc/TableFillingAndNavigationTools.hxx
@@ -75,6 +75,72 @@ public:
     void writeValue(double aValue);
 };
 
+class DataCellIterator
+{
+private:
+    ScRange mInputRange;
+    bool    mByColumn;
+    SCCOL   mCol;
+    SCROW   mRow;
+
+public:
+    DataCellIterator(ScRange aInputRange, bool aByColumn);
+    virtual ~DataCellIterator();
+
+    virtual bool hasNext();
+    virtual ScAddress get();
+    virtual void next();
+    virtual ScAddress getRelative(int aDelta);
+};
+
+class DataRangeIterator
+{
+protected:
+    ScRange   mInputRange;
+    sal_Int32 mIndex;
+
+public:
+    DataRangeIterator(ScRange aInputRange);
+    virtual ~DataRangeIterator();
+
+    virtual bool hasNext() = 0;
+    virtual ScRange get() = 0;
+    virtual void next() = 0;
+    virtual sal_Int32 index();
+
+    virtual DataCellIterator iterateCells() = 0;
+};
+
+class DataRangeByColumnIterator : public DataRangeIterator
+{
+protected:
+    SCCOL mCol;
+
+public:
+    DataRangeByColumnIterator(ScRange aInputRange);
+
+    virtual bool hasNext();
+    virtual void next();
+    virtual ScRange get();
+    virtual DataCellIterator iterateCells();
+};
+
+class DataRangeByRowIterator : public DataRangeIterator
+{
+protected:
+    SCROW mRow;
+
+public:
+    DataRangeByRowIterator(ScRange aInputRange);
+
+    virtual bool hasNext();
+    virtual void next();
+    virtual ScRange get();
+    virtual DataCellIterator iterateCells();
+};
+
+
+
 #endif
 
 
commit 2f823d458de726d8e8f7c3684e3b1f15d0104e27
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Tue Nov 5 22:03:56 2013 +0100

    Add tools to simplyfy adding formulas and cell navigation
    
    TableFillingAndNavigationTools were added to StatisticsDialogs which
    include FormulaTemplate and AddressWalkerWriter.
    FormulaTemplate simplyfies creting formulas and AddressWalkerWriter
    simplyfies navigating cells with relative address navigation and
    adding content (formulas, values, string) to cells.
    
    Change-Id: I32ecb4013f51bda9c8d0bf9f06b9f9dfd4da6def

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 1573eda..f763eda 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -480,6 +480,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
     sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog \
     sc/source/ui/StatisticsDialogs/SamplingDialog \
     sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog \
+    sc/source/ui/StatisticsDialogs/TableFillingAndNavigationTools \
     sc/source/ui/undo/areasave \
     sc/source/ui/undo/refundo \
     sc/source/ui/undo/target \
diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk
index bfe0346..61442aa 100644
--- a/sc/UIConfig_scalc.mk
+++ b/sc/UIConfig_scalc.mk
@@ -76,6 +76,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\
 	sc/uiconfig/scalc/ui/doubledialog \
 	sc/uiconfig/scalc/ui/erroralerttabpage \
 	sc/uiconfig/scalc/ui/externaldata \
+	sc/uiconfig/scalc/ui/exponentialsmoothingdialog \
 	sc/uiconfig/scalc/ui/filldlg \
 	sc/uiconfig/scalc/ui/footerdialog \
 	sc/uiconfig/scalc/ui/formatcellsdialog \
diff --git a/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
index 0559316..7709c5d 100644
--- a/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
@@ -23,13 +23,13 @@
 #include "random.hxx"
 #include "docfunc.hxx"
 #include "StatisticsDialogs.hrc"
+#include "TableFillingAndNavigationTools.hxx"
 
 #include "AnalysisOfVarianceDialog.hxx"
 
 namespace
 {
 
-
 static const char* lclBasicStatisticsLabels[] =
 {
     "Groups", "Count", "Sum", "Mean", "Variance", NULL
@@ -45,9 +45,9 @@ static const char* lclAnovaLabels[] =
     "Source of Variation", "SS", "df", "MS", "F", "P-value", "F critical", NULL
 };
 
-static const OUString lclWildcardNumber("%NUMBER%");
-static const OUString lclColumnLabelTemplate("Column %NUMBER%");
-static const OUString lclWildcardRange("%RANGE%");
+static const OUString strWildcardNumber("%NUMBER%");
+static const OUString strColumnLabelTemplate("Column %NUMBER%");
+static const OUString strWildcardRange("%RANGE%");
 
 OUString lclCreateMultiParameterFormula(
             ScRangeList&        aRangeList, const OUString& aFormulaTemplate,
@@ -75,7 +75,7 @@ ScAnalysisOfVarianceDialog::ScAnalysisOfVarianceDialog(
             pSfxBindings, pChildWindow, pParent, pViewData,
             "AnalysisOfVarianceDialog", "modules/scalc/ui/analysisofvariancedialog.ui" )
 {
-    get(mpAlpha,        "alpha-spin");
+    get(mpAlpha, "alpha-spin");
 }
 
 ScAnalysisOfVarianceDialog::~ScAnalysisOfVarianceDialog()
@@ -97,202 +97,166 @@ void ScAnalysisOfVarianceDialog::CalculateInputAndWriteToOutput( )
     ScAddress aStart = mInputRange.aStart;
     ScAddress aEnd   = mInputRange.aEnd;
 
-    SCTAB outTab = mOutputAddress.Tab();
-    SCCOL outCol = mOutputAddress.Col();
-    SCROW outRow = mOutputAddress.Row();
+    AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument);
+    FormulaTemplate aTemplate(mDocument, mAddressDetails);
 
-    OUString aReferenceString;
-    ScAddress aAddress;
+    SCROW inTab = aStart.Tab();
 
-    for (SCROW inTab = aStart.Tab(); inTab <= aEnd.Tab(); inTab++)
+    // Write labels
+    for(sal_Int32 i = 0; lclBasicStatisticsLabels[i] != NULL; i++)
     {
-        outCol = mOutputAddress.Col();
+        output.writeString(lclBasicStatisticsLabels[i]);
+        output.nextColumn();
+    }
+    output.nextRow();
 
-        // Write labels
-        for(sal_Int32 i = 0; lclBasicStatisticsLabels[i] != NULL; i++)
-        {
-            aAddress = ScAddress(outCol, outRow, outTab);
-            OUString aCalculationName(OUString::createFromAscii(lclBasicStatisticsLabels[i]));
-            pDocShell->GetDocFunc().SetStringCell(aAddress, aCalculationName, true);
-            outCol++;
-        }
-        outRow++;
+    ScRangeList aRangeList;
 
-        ScRangeList aRangeList;
+    // Write statistic formulas for columns
+    for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
+    {
+        output.resetColumn();
+        aTemplate.setTemplate(strColumnLabelTemplate);
+        aTemplate.applyString(strWildcardNumber, OUString::number(inCol - aStart.Col() + 1));
+        pDocShell->GetDocFunc().SetStringCell(output.current(), aTemplate.getTemplate(), true);
+        output.nextColumn();
 
-        // Write statistic formulas for columns
-        for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
-        {
-            outCol = mOutputAddress.Col();
-            aAddress = ScAddress(outCol, outRow, outTab);
-            OUString aNumberString = OUString::number(inCol - aStart.Col() + 1);
-            OUString aGroupName = lclColumnLabelTemplate.replaceAll(lclWildcardNumber, aNumberString);
-            pDocShell->GetDocFunc().SetStringCell(aAddress, aGroupName, true);
-            outCol++;
-
-            ScRange aColumnRange (
-                ScAddress(inCol, aStart.Row(), inTab),
-                ScAddress(inCol, aEnd.Row(), inTab)
-            );
-            aRangeList.Append(aColumnRange);
-
-            aReferenceString = aColumnRange.Format(SCR_ABS, mDocument, mAddressDetails);
-            OUString aFormulaString;
-            OUString aFormulaTemplate;
-
-            for(sal_Int32 i = 0; lclBasicStatisticsFormula[i] != NULL; i++)
-            {
-                aAddress = ScAddress(outCol, outRow, outTab);
-                aFormulaTemplate = OUString::createFromAscii(lclBasicStatisticsFormula[i]);
-                aFormulaString = aFormulaTemplate.replaceAll(lclWildcardRange, aReferenceString);
-                pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFormulaString), true);
-                outCol++;
-            }
-            outRow++;
-        }
+        ScRange aColumnRange(
+            ScAddress(inCol, aStart.Row(), inTab),
+            ScAddress(inCol, aEnd.Row(), inTab)
+        );
 
-        outRow++; // Blank row
+        aRangeList.Append(aColumnRange);
 
-        // Write ANOVA labels
-        outCol = mOutputAddress.Col();
-        for(sal_Int32 i = 0; lclAnovaLabels[i] != NULL; i++)
+        for(sal_Int32 i = 0; lclBasicStatisticsFormula[i] != NULL; i++)
         {
-            aAddress = ScAddress(outCol, outRow, outTab);
-            OUString aCalculationName(OUString::createFromAscii(lclAnovaLabels[i]));
-            pDocShell->GetDocFunc().SetStringCell(aAddress, aCalculationName, true);
-            outCol++;
+            aTemplate.setTemplate(lclBasicStatisticsFormula[i]);
+            aTemplate.applyRange(strWildcardRange, aColumnRange);
+            output.writeFormula(aTemplate.getTemplate());
+            output.nextColumn();
         }
-        outRow++;
+        output.nextRow();
+    }
 
-        // Between Groups
-        {
-            // Label
-            outCol = mOutputAddress.Col();
-            aAddress = ScAddress(outCol, outRow, outTab);
-            pDocShell->GetDocFunc().SetStringCell(aAddress, OUString("Between Groups"), true);
-            outCol++;
-
-            // Sum of Squares
-            aAddress = ScAddress(outCol, outRow, outTab);
-            ScAddress aAddressTotal(outCol, outRow+2, outTab);
-            OUString aReferenceTotal(aAddressTotal.Format(SCR_ABS, mDocument, mAddressDetails));
-            ScAddress aAddressWithin(outCol, outRow+1, outTab);
-            OUString aReferenceWithin(aAddressWithin.Format(SCR_ABS, mDocument, mAddressDetails));
-            OUString aFormulaString = "=" + aReferenceTotal + "-" + aReferenceWithin;
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFormulaString), true);
-            outCol++;
-
-            // Degree of freedom
-            aAddress = ScAddress(outCol, outRow, outTab);
-            aAddressTotal = ScAddress(outCol, outRow+2, outTab);
-            aReferenceTotal = aAddressTotal.Format(SCR_ABS, mDocument, mAddressDetails);
-            aAddressWithin = ScAddress(outCol, outRow+1, outTab);
-            aReferenceWithin = aAddressWithin.Format(SCR_ABS, mDocument, mAddressDetails);
-            aFormulaString = "=" + aReferenceTotal + "-" + aReferenceWithin;
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFormulaString), true);
-            outCol++;
-
-            // MS
-            OUString aSSRef(ScAddress(outCol-2, outRow, outTab).Format(SCR_ABS, mDocument, mAddressDetails));
-            OUString aDFRef(ScAddress(outCol-1, outRow, outTab).Format(SCR_ABS, mDocument, mAddressDetails));
-            aFormulaString = "=" + aSSRef + "/" + aDFRef;
-            aAddress = ScAddress(outCol, outRow, outTab);
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFormulaString), true);
-            outCol++;
-
-            // F
-            aAddress = ScAddress(outCol, outRow, outTab);
-            OUString aMSBetween(ScAddress(outCol-1, outRow, outTab).Format(SCR_ABS, mDocument, mAddressDetails));
-            OUString aMSWithin(ScAddress(outCol-1, outRow+1, outTab).Format(SCR_ABS, mDocument, mAddressDetails));
-            aFormulaString = "=" + aMSBetween + "/" + aMSWithin;
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFormulaString), true);
-            outCol++;
-
-            // P-value
-            aAddress = ScAddress(outCol, outRow, outTab);
-            OUString aFValue(ScAddress(outCol-1, outRow, outTab).Format(SCR_ABS, mDocument, mAddressDetails));
-            OUString aDFBetween(ScAddress(outCol-3, outRow, outTab).Format(SCR_ABS, mDocument, mAddressDetails));
-            OUString aDFWithin(ScAddress(outCol-3, outRow+1, outTab).Format(SCR_ABS, mDocument, mAddressDetails));
-            aFormulaString = "=FDIST("+ aFValue + ";" + aDFBetween + ";" + aDFWithin + ")";
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFormulaString), true);
-            outCol++;
-
-            // F critical
-            double aAlphaValue = mpAlpha->GetValue() / 100.0;
-            OUString aAlphaString = rtl::math::doubleToUString(
-                                        aAlphaValue, rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
-                                        ScGlobal::pLocaleData->getNumDecimalSep()[0], true);
-            aAddress = ScAddress(outCol, outRow, outTab);
-            aFormulaString = "=FINV(" + aAlphaString + ";" + aDFBetween + ";" + aDFWithin + ")";
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFormulaString), true);
-        }
-        outRow++;
+    output.nextRow(); // Blank row
 
-        // Within Groups
-        {
-            // Label
-            outCol = mOutputAddress.Col();
-            aAddress = ScAddress(outCol, outRow, outTab);
-            pDocShell->GetDocFunc().SetStringCell(aAddress, OUString("Within Groups"), true);
-            outCol++;
-
-            // Sum of Squares
-            aAddress = ScAddress(outCol, outRow, outTab);
-            OUString aSum("=SUM(%RANGE%)");
-            OUString aDevSQ("DEVSQ(%RANGE%)");
-            OUString aSSPart = lclCreateMultiParameterFormula(aRangeList, aDevSQ, lclWildcardRange, mDocument, mAddressDetails);
-            OUString aSS = aSum.replaceAll(lclWildcardRange, aSSPart);
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aSS), true);
-            outCol++;
-
-            // Degree of freedom
-            aAddress = ScAddress(outCol, outRow, outTab);
-            OUString aCountMinusOne("COUNT(%RANGE%)-1");
-            OUString aDFPart = lclCreateMultiParameterFormula(aRangeList, aCountMinusOne, lclWildcardRange, mDocument, mAddressDetails);
-            OUString aDF = aSum.replaceAll(lclWildcardRange, aDFPart);
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aDF), true);
-            outCol++;
-
-            // MS
-            ScAddress aAddressSS(outCol-2, outRow, outTab);
-            OUString aSSRef(aAddressSS.Format(SCR_ABS, mDocument, mAddressDetails));
-            ScAddress aAddressDF(outCol-1, outRow, outTab);
-            OUString aDFRef(aAddressDF.Format(SCR_ABS, mDocument, mAddressDetails));
-            OUString aFormulaString = "=" + aSSRef + "/" + aDFRef;
-            aAddress = ScAddress(outCol, outRow, outTab);
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFormulaString), true);
-        }
-        outRow++;
+    // Write ANOVA labels
+    output.resetColumn();
+    for(sal_Int32 i = 0; lclAnovaLabels[i] != NULL; i++)
+    {
+        output.writeString(lclAnovaLabels[i]);
+        output.nextColumn();
+    }
+    output.nextRow();
 
-        // Total
-        {
-            // Label
-            outCol = mOutputAddress.Col();
-            aAddress = ScAddress(outCol, outRow, outTab);
-            pDocShell->GetDocFunc().SetStringCell(aAddress, OUString("Total"), true);
-            outCol++;
-
-            // Sum of Squares
-            OUString aDevSQ("DEVSQ(%RANGE%)");
-            aRangeList.Format( aReferenceString, SCR_ABS, mDocument );
-            OUString aFormulaString = aDevSQ.replaceAll(lclWildcardRange, aReferenceString);
-
-            aAddress = ScAddress(outCol, outRow, outTab);
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, "=" + aFormulaString), true);
-            outCol++;
-
-            // Degree of freedom
-            aAddress = ScAddress(outCol, outRow, outTab);
-            OUString aCount("COUNT(%RANGE%)");
-            OUString aSumMinusOne("=SUM(%RANGE%)-1");
-            OUString aDFPart = lclCreateMultiParameterFormula(aRangeList, aCount, lclWildcardRange, mDocument, mAddressDetails);
-            OUString aDF = aSumMinusOne.replaceAll(lclWildcardRange, aDFPart);
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aDF), true);
-        }
-        outRow++;
+    // Between Groups
+    {
+        // Label
+        output.resetColumn();
+        output.writeString("Between Groups");
+        output.nextColumn();
+
+        // Sum of Squares
+        aTemplate.setTemplate("=%TOTAL% - %WITHIN%");
+        aTemplate.applyAddress("%TOTAL%", output.current(0, 2));
+        aTemplate.applyAddress("%WITHIN%", output.current(0, 1));
+        output.writeFormula(aTemplate.getTemplate());
+        output.nextColumn();
+
+        // Degree of freedom
+        aTemplate.setTemplate("=%TOTAL% - %WITHIN%");
+        aTemplate.applyAddress("%TOTAL%", output.current(0, 2));
+        aTemplate.applyAddress("%WITHIN%", output.current(0, 1));
+        output.writeFormula(aTemplate.getTemplate());
+        output.nextColumn();
+
+        // MS
+        aTemplate.setTemplate("=%SS_REF% / %DF_REF%");
+        aTemplate.applyAddress("%SS_REF%", output.current(-2, 0));
+        aTemplate.applyAddress("%DF_REF%", output.current(-1, 0));
+        output.writeFormula(aTemplate.getTemplate());
+        output.nextColumn();
+
+        // F
+        aTemplate.setTemplate("=%MS_BETWEEN% / %MS_WITHIN%");
+        aTemplate.applyAddress("%MS_BETWEEN%", output.current(-1, 0));
+        aTemplate.applyAddress("%MS_WITHIN%",  output.current(-1, 1));
+        output.writeFormula(aTemplate.getTemplate());
+        output.nextColumn();
+
+        // P-value
+        aTemplate.setTemplate("=FDIST(%F_VAL%; %DF_BETWEEN%; %DF_WITHIN%");
+        aTemplate.applyAddress("%F_VAL%",       output.current(-1, 0));
+        aTemplate.applyAddress("%DF_BETWEEN%",  output.current(-3, 0));
+        aTemplate.applyAddress("%DF_WITHIN%",   output.current(-3, 1));
+        output.writeFormula(aTemplate.getTemplate());
+        output.nextColumn();
+
+        // F critical
+        double aAlphaValue = mpAlpha->GetValue() / 100.0;
+        OUString aAlphaString = rtl::math::doubleToUString(
+                                    aAlphaValue, rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
+                                    ScGlobal::pLocaleData->getNumDecimalSep()[0], true);
+
+        aTemplate.setTemplate("=FINV(%ALPHA%; %DF_BETWEEN%; %DF_WITHIN%");
+        aTemplate.applyString("%ALPHA%",       aAlphaString);
+        aTemplate.applyAddress("%DF_BETWEEN%", output.current(-4, 0));
+        aTemplate.applyAddress("%DF_WITHIN%",  output.current(-4, 1));
+        output.writeFormula(aTemplate.getTemplate());
+    }
+    output.nextRow();
+
+    // Within Groups
+    {
+        // Label
+        output.resetColumn();
+        output.writeString("Within Groups");
+        output.nextColumn();
+
+        // Sum of Squares
+        OUString aSSPart = lclCreateMultiParameterFormula(aRangeList, OUString("DEVSQ(%RANGE%)"), strWildcardRange, mDocument, mAddressDetails);
+        aTemplate.setTemplate("=SUM(%RANGE%)");
+        aTemplate.applyString(strWildcardRange, aSSPart);
+        output.writeFormula(aTemplate.getTemplate());
+        output.nextColumn();
+
+        // Degree of freedom
+        OUString aDFPart = lclCreateMultiParameterFormula(aRangeList, OUString("COUNT(%RANGE%)-1"), strWildcardRange, mDocument, mAddressDetails);
+        aTemplate.setTemplate("=SUM(%RANGE%)");
+        aTemplate.applyString(strWildcardRange, aDFPart);
+        output.writeFormula(aTemplate.getTemplate());
+        output.nextColumn();
+
+        // MS
+        aTemplate.setTemplate("=%SS% / %DF%");
+        aTemplate.applyAddress("%SS%", output.current(-2, 0));
+        aTemplate.applyAddress("%DF%", output.current(-1, 0));
+        output.writeFormula(aTemplate.getTemplate());
+    }
+    output.nextRow();
+
+    // Total
+    {
+        // Label
+        output.resetColumn();
+        output.writeString("Total");
+        output.nextColumn();
+
+        // Sum of Squares
+        aTemplate.setTemplate("=DEVSQ(%RANGE%)");
+        aTemplate.applyRangeList(strWildcardRange, aRangeList);
+        output.writeFormula(aTemplate.getTemplate());
+        output.nextColumn();
+
+        // Degree of freedom
+        OUString aDFPart = lclCreateMultiParameterFormula(aRangeList, "COUNT(%RANGE%)", strWildcardRange, mDocument, mAddressDetails);
+        aTemplate.setTemplate("=SUM(%RANGE%) - 1");
+        aTemplate.applyString(strWildcardRange, aDFPart);
+        output.writeFormula(aTemplate.getTemplate());
     }
+    output.nextRow();
 
-    ScRange aOutputRange(mOutputAddress, ScAddress(outTab, outRow, outTab) );
+    ScRange aOutputRange(output.mMinimumAddress, output.mMaximumAddress);
     pUndoManager->LeaveListAction();
     pDocShell->PostPaint( aOutputRange, PAINT_GRID );
 }
diff --git a/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx b/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
index 80d1b87..19b4788 100644
--- a/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.cxx
@@ -11,6 +11,7 @@
 #include <sfx2/dispatch.hxx>
 #include <svl/zforlist.hxx>
 #include <svl/undo.hxx>
+#include <boost/random.hpp>
 
 #include "formulacell.hxx"
 #include "rangelst.hxx"
@@ -23,8 +24,7 @@
 #include "random.hxx"
 #include "docfunc.hxx"
 #include "StatisticsDialogs.hrc"
-
-#include <boost/random.hpp>
+#include "TableFillingAndNavigationTools.hxx"
 
 #include "DescriptiveStatisticsDialog.hxx"
 
@@ -32,8 +32,8 @@ namespace
 {
 
 struct StatisticCalculation {
-    sal_Int16 aCalculationNameId;
-    const char*     aFormula;
+    sal_Int16   aCalculationNameId;
+    const char* aFormula;
 };
 
 static const StatisticCalculation lclCalcDefinitions[] =
@@ -76,61 +76,47 @@ sal_Bool ScDescriptiveStatisticsDialog::Close()
 
 void ScDescriptiveStatisticsDialog::CalculateInputAndWriteToOutput( )
 {
-    OUString aUndo(SC_RESSTR(STR_DESCRIPTIVE_STATISTICS_UNDO_NAME));
+    OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, STR_DESCRIPTIVE_STATISTICS_UNDO_NAME));
     ScDocShell* pDocShell = mViewData->GetDocShell();
     svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
     pUndoManager->EnterListAction( aUndo, aUndo );
 
-    ScAddress aStart = mInputRange.aStart;
-    ScAddress aEnd   = mInputRange.aEnd;
+    OUString aReferenceString;
 
-    SCTAB outTab = mOutputAddress.Tab();
-    SCCOL outCol = mOutputAddress.Col();
-    SCROW outRow = mOutputAddress.Row();
+    AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument);
+    FormulaTemplate aTemplate(mDocument, mAddressDetails);
 
-    OUString aReferenceString;
-    ScAddress aAddress;
+    SCROW inTab = mInputRange.aStart.Tab();
+
+    for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
+    {
+        OUString aLabel(SC_STRLOAD(RID_STATISTICS_DLGS, lclCalcDefinitions[i].aCalculationNameId));
+        aOutput.writeString(aLabel);
+        aOutput.nextRow();
+    }
+    aOutput.nextColumn();
 
-    for (SCROW inTab = aStart.Tab(); inTab <= aEnd.Tab(); inTab++)
+    for (SCCOL inCol = mInputRange.aStart.Col(); inCol <= mInputRange.aEnd.Col(); inCol++)
     {
-        outCol = mOutputAddress.Col();
+        aOutput.resetRow();
 
-        for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
-        {
-            aAddress = ScAddress(outCol, outRow, outTab);
-            OUString aCalculationName(SC_RESSTR(lclCalcDefinitions[i].aCalculationNameId));
-            pDocShell->GetDocFunc().SetStringCell(aAddress, aCalculationName, true);
-            outRow++;
-        }
-        outCol++;
+        ScRange aColumnRange(
+            ScAddress(inCol, mInputRange.aStart.Row(), inTab),
+            ScAddress(inCol, mInputRange.aEnd.Row(), inTab)
+        );
 
-        for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
+        for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
         {
-            outRow = mOutputAddress.Row();
-            ScRange aColumnRange (
-                ScAddress(inCol, mInputRange.aStart.Row(), inTab),
-                ScAddress(inCol, mInputRange.aEnd.Row(), inTab)
-            );
-
-            aReferenceString = aColumnRange.Format(SCR_ABS, mDocument, mAddressDetails);
-            OUString aFormulaString;
-            OUString aFormulaTemplate;
-
-            for(sal_Int32 i = 0; lclCalcDefinitions[i].aFormula != NULL; i++)
-            {
-                aAddress = ScAddress(outCol, outRow, outTab);
-                aFormulaTemplate = OUString::createFromAscii(lclCalcDefinitions[i].aFormula);
-                aFormulaString = aFormulaTemplate.replaceAll(strWildcardRange, aReferenceString);
-                pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFormulaString), true);
-                outRow++;
-            }
-            outCol++;
+            aTemplate.setTemplate(lclCalcDefinitions[i].aFormula);
+            aTemplate.applyRange(strWildcardRange, aColumnRange);
+            aOutput.writeFormula(aTemplate.getTemplate());
+            aOutput.nextRow();
         }
-        outTab++;
+        aOutput.nextColumn();
     }
 
-    ScRange aOutputRange(mOutputAddress, ScAddress(outTab, outRow, outTab) );
     pUndoManager->LeaveListAction();
+    ScRange aOutputRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
     pDocShell->PostPaint( aOutputRange, PAINT_GRID );
 }
 
diff --git a/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx b/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
index 3ba32e4..9afeb48 100644
--- a/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog.cxx
@@ -19,56 +19,23 @@
 #include "document.hxx"
 #include "uiitems.hxx"
 #include "reffact.hxx"
-#include "scresid.hxx"
+#include "strload.hxx"
+#include "random.hxx"
 #include "docfunc.hxx"
-#include "globstr.hrc"
-#include "sc.hrc"
+#include "StatisticsDialogs.hrc"
+#include "TableFillingAndNavigationTools.hxx"
 
 #include "ExponentialSmoothingDialog.hxx"
 
-namespace
-{
-    static const OUString strWildcardRange("%RANGE%");
-
-    class Template
-    {
-    public:
-        OUString            mTemplate;
-        ScDocument*         mDocument;
-        ScAddress::Details  mAddressDetails;
-
-        Template(ScDocument* aDocument, ScAddress::Details aAddressDetails) :
-            mDocument(aDocument),
-            mAddressDetails(aAddressDetails)
-        {}
-
-        void setTemplate(OUString aTemplate)
-        {
-            mTemplate = aTemplate;
-        }
-
-        OUString& getTemplate()
-        {
-            return mTemplate;
-        }
-
-        void applyRange(OUString aVariable, ScRange& aRange)
-        {
-            OUString aRangeString = aRange.Format(SCR_ABS, mDocument, mAddressDetails);
-
-            mTemplate = mTemplate.replaceAll(aVariable, aRangeString);
-        }
-
-    };
-}
-
 ScExponentialSmoothingDialog::ScExponentialSmoothingDialog(
                     SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
                     Window* pParent, ScViewData* pViewData ) :
     ScStatisticsInputOutputDialog(
             pSfxBindings, pChildWindow, pParent, pViewData,
-            "DescriptiveStatisticsDialog", "modules/scalc/ui/descriptivestatisticsdialog.ui" )
-{}
+            "ExponentialSmoothingDialog", "modules/scalc/ui/exponentialsmoothingdialog.ui" )
+{
+    get(mpSmoothingFactor, "smoothing-factor-spin");
+}
 
 ScExponentialSmoothingDialog::~ScExponentialSmoothingDialog()
 {}
@@ -80,7 +47,7 @@ sal_Bool ScExponentialSmoothingDialog::Close()
 
 void ScExponentialSmoothingDialog::CalculateInputAndWriteToOutput( )
 {
-    OUString aUndo("Exponential");
+    OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, STR_EXPONENTIAL_SMOOTHING_UNDO_NAME));
     ScDocShell* pDocShell = mViewData->GetDocShell();
     svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
     pUndoManager->EnterListAction( aUndo, aUndo );
@@ -88,29 +55,24 @@ void ScExponentialSmoothingDialog::CalculateInputAndWriteToOutput( )
     ScAddress aStart = mInputRange.aStart;
     ScAddress aEnd   = mInputRange.aEnd;
 
-    SCTAB outTab = mOutputAddress.Tab();
-    SCCOL outCol = mOutputAddress.Col();
-    SCROW outRow = mOutputAddress.Row();
-
-    ScAddress aAddress;
+    AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument);
+    FormulaTemplate aTemplate(mDocument, mAddressDetails);
 
     SCROW inTab = aStart.Tab();
 
-    Template aTemplate(mDocument, mAddressDetails);
+    // Smoothing factor
+    double aSmoothingFactor = mpSmoothingFactor->GetValue() / 100.0;
 
-    // Dampning factor
-    ScAddress aDampFactorAddress(outCol, outRow, outTab);
-    pDocShell->GetDocFunc().SetValueCell(aDampFactorAddress, 0.2, true);
-    OUString aDampFactorAddressString = aDampFactorAddress.Format(SCR_ABS, mDocument, mAddressDetails);
-    outRow++;
+    ScAddress aSmoothingFactorAddress = output.current();
+    output.writeValue(aSmoothingFactor);
+    output.nextRow();
 
     // Exponential Smoothing
-    SCROW firstOutRow = outRow;
+    output.push();
 
     for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
     {
-        outRow = firstOutRow;
-        aAddress = ScAddress(outCol, outRow, outTab);
+        output.resetRow();
 
         SCROW inRow = aStart.Row();
 
@@ -120,46 +82,36 @@ void ScExponentialSmoothingDialog::CalculateInputAndWriteToOutput( )
                     ScAddress(inCol, mInputRange.aStart.Row(), inTab),
                     ScAddress(inCol, mInputRange.aEnd.Row(), inTab));
 
-            OUString aAverageFormulaTemplate = OUString("=AVERAGE(%RANGE%)");
-            OUString aColumnRangeString = aColumnRange.Format(SCR_ABS, mDocument, mAddressDetails);
-            OUString aAverageFormulaString = aAverageFormulaTemplate.replaceAll(OUString("%RANGE%"), aColumnRangeString);
-
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aAverageFormulaString), true);
+            aTemplate.setTemplate("=AVERAGE(%RANGE%)");
+            aTemplate.applyRange("%RANGE%", aColumnRange);
+            output.writeFormula(aTemplate.getTemplate());
         }
         else
         {
             ScAddress aFirstValueAddress(inCol, mInputRange.aStart.Row(), inTab);
-            OUString aFirstValueAddressString = aFirstValueAddress.Format(SCR_ABS, mDocument, mAddressDetails);
-            OUString aFirstValueFormulaTemplate = OUString("=%RANGE%");
-            OUString aFistValueString = aFirstValueFormulaTemplate.replaceAll(OUString("%RANGE%"), aFirstValueAddressString);
-            pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFistValueString), true);
+
+            aTemplate.setTemplate("=%VAR%");
+            aTemplate.applyAddress("%VAR%", aFirstValueAddress);
+            output.writeFormula(aTemplate.getTemplate());
         }
 
-        outRow++;
+        output.nextRow();
 
         for (inRow = aStart.Row() + 1; inRow <= aEnd.Row(); inRow++)
         {
-            ScAddress aPreviousInputAddress(inCol,   inRow  - 1, inTab);
-            ScAddress aPreviousOutputAddress(outCol, outRow - 1, outTab);
-
-            OUString aPreviousInputAddressString  = aPreviousInputAddress.Format(SCR_ABS, mDocument, mAddressDetails);

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list