[Libreoffice-commits] core.git: 2 commits - officecfg/registry sc/AllLangResTarget_sc.mk sc/inc sc/Library_sc.mk sc/sdi sc/source sc/uiconfig svx/source

Tomaž Vajngerl quikee at gmail.com
Sun Jul 28 02:52:14 PDT 2013


 officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu |   16 +
 sc/AllLangResTarget_sc.mk                                         |    3 
 sc/Library_sc.mk                                                  |    2 
 sc/inc/globstr.hrc                                                |    5 
 sc/inc/sc.hrc                                                     |    2 
 sc/sdi/cellsh.sdi                                                 |    2 
 sc/sdi/scalc.sdi                                                  |   48 +++
 sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx       |    9 
 sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.src       |   19 +
 sc/source/ui/StatisticsDialogs/CorrelationDialog.cxx              |  160 ++++++++++
 sc/source/ui/StatisticsDialogs/CorrelationDialog.src              |   19 +
 sc/source/ui/StatisticsDialogs/CovarianceDialog.cxx               |  159 +++++++++
 sc/source/ui/StatisticsDialogs/CovarianceDialog.src               |   19 +
 sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx    |   28 +
 sc/source/ui/app/scdll.cxx                                        |    2 
 sc/source/ui/inc/CorrelationDialog.hxx                            |   43 ++
 sc/source/ui/inc/CovarianceDialog.hxx                             |   43 ++
 sc/source/ui/inc/StatisticsInputOutputDialog.hxx                  |    4 
 sc/source/ui/inc/reffact.hxx                                      |   13 
 sc/source/ui/view/cellsh.cxx                                      |    2 
 sc/source/ui/view/cellsh1.cxx                                     |   18 +
 sc/source/ui/view/tabvwsh.cxx                                     |    3 
 sc/source/ui/view/tabvwshc.cxx                                    |   15 
 sc/uiconfig/scalc/menubar/menubar.xml                             |    2 
 svx/source/dialog/svxruler.cxx                                    |    9 
 25 files changed, 638 insertions(+), 7 deletions(-)

New commits:
commit 8e4f4fb541277e35aca7d8f210307635f7a81443
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Sun Jul 28 11:45:56 2013 +0200

    fdo#66477 Add correlation and covariance to Calc.
    
    Change-Id: I877199aa9c0bb275fa678488548c7e6797c0eefc

diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index e602c13..1bea73a 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
@@ -661,6 +661,22 @@
           <value>1</value>
         </prop>
       </node>
+      <node oor:name=".uno:CorrelationDialog" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">~Correlation...</value>
+        </prop>
+        <prop oor:name="Properties" oor:type="xs:int">
+          <value>1</value>
+        </prop>
+      </node>
+      <node oor:name=".uno:CovarianceDialog" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">~Covariance...</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/AllLangResTarget_sc.mk b/sc/AllLangResTarget_sc.mk
index 88f60ad..5f43eb3 100644
--- a/sc/AllLangResTarget_sc.mk
+++ b/sc/AllLangResTarget_sc.mk
@@ -83,6 +83,9 @@ $(eval $(call gb_SrsTarget_add_files,sc/res,\
     sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog.src \
     sc/source/ui/StatisticsDialogs/SamplingDialog.src \
     sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog.src \
+    sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.src \
+    sc/source/ui/StatisticsDialogs/CorrelationDialog.src \
+    sc/source/ui/StatisticsDialogs/CovarianceDialog.src \
     sc/source/core/src/compiler.src \
 ))
 
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 72a83a5..6f559f5 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -478,6 +478,8 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
 	sc/source/ui/StatisticsDialogs/SamplingDialog \
 	sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog \
 	sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog \
+	sc/source/ui/StatisticsDialogs/CorrelationDialog \
+	sc/source/ui/StatisticsDialogs/CovarianceDialog \
 	sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog \
 	sc/source/ui/undo/areasave \
 	sc/source/ui/undo/refundo \
diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index 7a7cf0a..2f8e562 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -720,7 +720,10 @@
 #define SID_CALC_SUM            585
 #define SID_CALC_COUNT          586
 
-#define STR_DESCRIPTIVE_STATISTICS_UNDO_NAME  587
+#define STR_DESCRIPTIVE_STATISTICS_UNDO_NAME    587
+#define STR_ANALYSIS_OF_VARIANCE_UNDO_NAME      588
+#define STR_CORRELATION_UNDO_NAME               589
+#define STR_COVARIANCE_UNDO_NAME                590
 
 
 #endif
diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index 7ee45d0..8611337 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -256,6 +256,8 @@
 #define SID_SAMPLING_DIALOG                 (SC_MESSAGE_START + 71)
 #define SID_DESCRIPTIVE_STATISTICS_DIALOG   (SC_MESSAGE_START + 72)
 #define SID_ANALYSIS_OF_VARIANCE_DIALOG     (SC_MESSAGE_START + 73)
+#define SID_CORRELATION_DIALOG              (SC_MESSAGE_START + 74)
+#define SID_COVARIANCE_DIALOG               (SC_MESSAGE_START + 75)
 
 // functions
 
diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi
index 31ff7f0..d9e1893 100644
--- a/sc/sdi/cellsh.sdi
+++ b/sc/sdi/cellsh.sdi
@@ -151,6 +151,8 @@ interface CellSelection
     SID_SAMPLING_DIALOG                 [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
     SID_DESCRIPTIVE_STATISTICS_DIALOG   [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
     SID_ANALYSIS_OF_VARIANCE_DIALOG     [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
+    SID_CORRELATION_DIALOG              [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
+    SID_COVARIANCE_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 0a7c0eb..2f5024a 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -3038,6 +3038,54 @@ SfxVoidItem AnalysisOfVarianceDialog SID_ANALYSIS_OF_VARIANCE_DIALOG
     GroupId = GID_OPTIONS;
 ]
 
+SfxVoidItem CorrelationDialog SID_CORRELATION_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 CovarianceDialog SID_COVARIANCE_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/AnalysisOfVarianceDialog.cxx b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
index 2c7325a..20d2c86 100644
--- a/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.cxx
@@ -30,6 +30,7 @@
 namespace
 {
 
+
 static const char* lclBasicStatisticsLabels[] =
 {
     "Groups", "Count", "Sum", "Mean", "Variance", NULL
@@ -45,6 +46,8 @@ 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%");
 
 OUString lclCreateMultiParameterFormula(
@@ -87,7 +90,8 @@ sal_Bool ScAnalysisOfVarianceDialog::Close()
 
 void ScAnalysisOfVarianceDialog::CalculateInputAndWriteToOutput( )
 {
-    OUString aUndo("Analysis Of Variance");
+    OUString aUndo(SC_RESSTR(STR_ANALYSIS_OF_VARIANCE_UNDO_NAME));
+
     ScDocShell* pDocShell = mViewData->GetDocShell();
     svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
     pUndoManager->EnterListAction( aUndo, aUndo );
@@ -123,7 +127,8 @@ void ScAnalysisOfVarianceDialog::CalculateInputAndWriteToOutput( )
         {
             outCol = mOutputAddress.Col();
             aAddress = ScAddress(outCol, outRow, outTab);
-            OUString aGroupName = OUString("Column ") + OUString::number(inCol - aStart.Col() + 1);
+            OUString aNumberString = OUString::number(inCol - aStart.Col() + 1);
+            OUString aGroupName = lclColumnLabelTemplate.replaceAll(lclWildcardNumber, aNumberString);
             pDocShell->GetDocFunc().SetStringCell(aAddress, aGroupName, true);
             outCol++;
 
diff --git a/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.src b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.src
new file mode 100644
index 0000000..dffcb11
--- /dev/null
+++ b/sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog.src
@@ -0,0 +1,19 @@
+/* -*- 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 "globstr.hrc"
+
+String STR_ANALYSIS_OF_VARIANCE_UNDO_NAME
+{
+    Text [ en-US ] = "Analysis of Variance";
+};
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/CorrelationDialog.cxx b/sc/source/ui/StatisticsDialogs/CorrelationDialog.cxx
new file mode 100644
index 0000000..9f26c8c
--- /dev/null
+++ b/sc/source/ui/StatisticsDialogs/CorrelationDialog.cxx
@@ -0,0 +1,160 @@
+/* -*- 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 "scresid.hxx"
+#include "random.hxx"
+#include "docfunc.hxx"
+#include "globstr.hrc"
+#include "sc.hrc"
+
+#include "CorrelationDialog.hxx"
+
+namespace
+{
+
+static const OUString lclWildcardColumn1("%COLUMN1%");
+static const OUString lclWildcardColumn2("%COLUMN2%");
+static const OUString lclCorrelTemplate("=CORREL(%COLUMN1%, %COLUMN2%)");
+static const OUString lclWildcardNumber("%NUMBER%");
+static const OUString lclColumnLabelTemplate("Column %NUMBER%");
+
+}
+
+ScCorrelationDialog::ScCorrelationDialog(
+                    SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
+                    Window* pParent, ScViewData* pViewData ) :
+    ScStatisticsInputOutputDialog(
+            pSfxBindings, pChildWindow, pParent, pViewData,
+            "DescriptiveStatisticsDialog", "modules/scalc/ui/descriptivestatisticsdialog.ui" )
+{}
+
+ScCorrelationDialog::~ScCorrelationDialog()
+{}
+
+sal_Bool ScCorrelationDialog::Close()
+{
+    return DoClose( ScCorrelationDialogWrapper::GetChildWindowId() );
+}
+
+void ScCorrelationDialog::CalculateInputAndWriteToOutput( )
+{
+    OUString aUndo(SC_RESSTR(STR_CORRELATION_UNDO_NAME));
+    ScDocShell* pDocShell = mViewData->GetDocShell();
+    svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
+    pUndoManager->EnterListAction( aUndo, aUndo );
+
+    ScAddress aStart = mInputRange.aStart;
+    ScAddress aEnd   = mInputRange.aEnd;
+
+    SCTAB outTab = mOutputAddress.Tab();
+    SCCOL outCol = mOutputAddress.Col();
+    SCROW outRow = mOutputAddress.Row();
+
+    ScAddress aAddress;
+    SCCOL aMaxCol = 0;
+    SCROW aMaxRow = 0;
+
+    for (SCTAB inTab = aStart.Tab(); inTab <= aEnd.Tab(); inTab++)
+    {
+        ScRangeList aRangeList = MakeColumnRangeList(inTab, aStart, aEnd);
+
+        // column labels
+        aAddress = ScAddress(outCol, outRow, outTab);
+        pDocShell->GetDocFunc().SetStringCell(aAddress, OUString("Correlations"), true);
+        outCol++;
+        aMaxCol = outCol > aMaxCol ? outCol : aMaxCol;
+
+        // write labels to columns
+        for (size_t i = 0; i < aRangeList.size(); i++)
+        {
+            aAddress = ScAddress(outCol, outRow, outTab);
+            OUString aColumnLabel = lclColumnLabelTemplate.replaceAll(lclWildcardNumber, OUString::number(i + 1));
+            pDocShell->GetDocFunc().SetStringCell(aAddress, aColumnLabel, true);
+            outCol++;
+            aMaxCol = outCol > aMaxCol ? outCol : aMaxCol;
+        }
+
+        // write labels to rows
+        outCol = mOutputAddress.Col();
+        outRow++;
+        for (size_t i = 0; i < aRangeList.size(); i++)
+        {
+            aAddress = ScAddress(outCol, outRow, outTab);
+            OUString aColumnLabel = lclColumnLabelTemplate.replaceAll(lclWildcardNumber, OUString::number(i + 1));
+            pDocShell->GetDocFunc().SetStringCell(aAddress, aColumnLabel, true);
+            outRow++;
+            aMaxRow = outRow > aMaxRow ? outRow : aMaxRow;
+        }
+
+        // write correlation formulas
+        aAddress = ScAddress(
+                    mOutputAddress.Col() + 1,
+                    mOutputAddress.Row() + 1,
+                    inTab);
+
+        WriteCorrelationFormulas(aAddress, aRangeList);
+        outTab++;
+    }
+    ScAddress aLastAddress = ScAddress(
+                                mOutputAddress.Col() + aMaxCol,
+                                mOutputAddress.Row() + aMaxRow,
+                                outTab);
+
+    ScRange aOutputRange(mOutputAddress, aLastAddress);
+    pUndoManager->LeaveListAction();
+    pDocShell->PostPaint(aOutputRange, PAINT_GRID);
+}
+
+void ScCorrelationDialog::WriteCorrelationFormulas(ScAddress aOutputAddress, ScRangeList aRangeList)
+{
+    ScDocShell* pDocShell = mViewData->GetDocShell();
+    OUString aColumnString1;
+    OUString aColumnString2;
+    ScAddress aAddress;
+
+    SCTAB outTab = aOutputAddress.Tab();
+    SCCOL outCol = aOutputAddress.Col();
+
+    OUString aFormulaString;
+
+    for (size_t i = 0; i < aRangeList.size(); i++)
+    {
+        SCROW outRow = aOutputAddress.Row();
+        for (size_t j = 0; j < aRangeList.size(); j++)
+        {
+            if (j >= i)
+            {
+                aRangeList[i]->Format( aColumnString1, SCR_ABS, mDocument, mAddressDetails );
+                aRangeList[j]->Format( aColumnString2, SCR_ABS, mDocument, mAddressDetails );
+
+                aAddress = ScAddress(outCol, outRow, outTab);
+                aFormulaString = lclCorrelTemplate.replaceAll(lclWildcardColumn1, aColumnString1);
+                aFormulaString = aFormulaString.replaceAll(lclWildcardColumn2, aColumnString2);
+                pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFormulaString), true);
+            }
+            outRow++;
+        }
+        outCol++;
+    }
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/CorrelationDialog.src b/sc/source/ui/StatisticsDialogs/CorrelationDialog.src
new file mode 100644
index 0000000..84e7e39
--- /dev/null
+++ b/sc/source/ui/StatisticsDialogs/CorrelationDialog.src
@@ -0,0 +1,19 @@
+/* -*- 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 "globstr.hrc"
+
+String STR_CORRELATION_UNDO_NAME
+{
+    Text [ en-US ] = "Correlation";
+};
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/CovarianceDialog.cxx b/sc/source/ui/StatisticsDialogs/CovarianceDialog.cxx
new file mode 100644
index 0000000..94a62da
--- /dev/null
+++ b/sc/source/ui/StatisticsDialogs/CovarianceDialog.cxx
@@ -0,0 +1,159 @@
+/* -*- 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 "scresid.hxx"
+#include "random.hxx"
+#include "docfunc.hxx"
+#include "globstr.hrc"
+#include "sc.hrc"
+
+#include "CovarianceDialog.hxx"
+
+namespace
+{
+
+static const OUString lclWildcardRow1("%ROW1%");
+static const OUString lclWildcardRow2("%ROW2%");
+static const OUString lclCovarTemplate("=COVAR(%ROW1%, %ROW2%)");
+static const OUString lclWildcardNumber("%NUMBER%");
+static const OUString lclRowLabelTemplate("Row %NUMBER%");
+
+}
+
+ScCovarianceDialog::ScCovarianceDialog(
+                    SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
+                    Window* pParent, ScViewData* pViewData ) :
+    ScStatisticsInputOutputDialog(
+            pSfxBindings, pChildWindow, pParent, pViewData,
+            "DescriptiveStatisticsDialog", "modules/scalc/ui/descriptivestatisticsdialog.ui" )
+{}
+
+ScCovarianceDialog::~ScCovarianceDialog()
+{}
+
+sal_Bool ScCovarianceDialog::Close()
+{
+    return DoClose( ScCovarianceDialogWrapper::GetChildWindowId() );
+}
+
+void ScCovarianceDialog::CalculateInputAndWriteToOutput( )
+{
+    OUString aUndo(SC_RESSTR(STR_COVARIANCE_UNDO_NAME));
+    ScDocShell* pDocShell = mViewData->GetDocShell();
+    svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
+    pUndoManager->EnterListAction( aUndo, aUndo );
+
+    ScAddress aStart = mInputRange.aStart;
+    ScAddress aEnd   = mInputRange.aEnd;
+
+    SCTAB outTab = mOutputAddress.Tab();
+    SCCOL outCol = mOutputAddress.Col();
+    SCROW outRow = mOutputAddress.Row();
+
+    ScAddress aAddress;
+    SCCOL aMaxCol = 0;
+    SCROW aMaxRow = 0;
+
+    for (SCTAB inTab = aStart.Tab(); inTab <= aEnd.Tab(); inTab++)
+    {
+        ScRangeList aRangeList = MakeRowRangeList(inTab, aStart, aEnd);
+
+        // row labels
+        aAddress = ScAddress(outCol, outRow, outTab);
+        pDocShell->GetDocFunc().SetStringCell(aAddress, OUString("Covariances"), true);
+        outCol++;
+        aMaxCol = outCol > aMaxCol ? outCol : aMaxCol;
+
+        // write labels to columns
+        for (size_t i = 0; i < aRangeList.size(); i++)
+        {
+            aAddress = ScAddress(outCol, outRow, outTab);
+            OUString aRowLabel = lclRowLabelTemplate.replaceAll(lclWildcardNumber, OUString::number(i + 1));
+            pDocShell->GetDocFunc().SetStringCell(aAddress, aRowLabel, true);
+            outCol++;
+            aMaxCol = outCol > aMaxCol ? outCol : aMaxCol;
+        }
+
+        // write labels to rows
+        outCol = mOutputAddress.Col();
+        outRow++;
+        for (size_t i = 0; i < aRangeList.size(); i++)
+        {
+            aAddress = ScAddress(outCol, outRow, outTab);
+            OUString aRowLabel = lclRowLabelTemplate.replaceAll(lclWildcardNumber, OUString::number(i + 1));
+            pDocShell->GetDocFunc().SetStringCell(aAddress, aRowLabel, true);
+            outRow++;
+            aMaxRow = outRow > aMaxRow ? outRow : aMaxRow;
+        }
+
+        // write correlation formulas
+        aAddress = ScAddress(
+                    mOutputAddress.Col() + 1,
+                    mOutputAddress.Row() + 1,
+                    inTab);
+
+        WriteCovarianceFormulas(aAddress, aRangeList);
+        outTab++;
+    }
+    ScAddress aLastAddress = ScAddress(
+                                mOutputAddress.Col() + aMaxCol,
+                                mOutputAddress.Row() + aMaxRow,
+                                outTab);
+
+    ScRange aOutputRange(mOutputAddress, aLastAddress);
+    pUndoManager->LeaveListAction();
+    pDocShell->PostPaint(aOutputRange, PAINT_GRID);
+}
+
+void ScCovarianceDialog::WriteCovarianceFormulas(ScAddress aOutputAddress, ScRangeList aRangeList)
+{
+    ScDocShell* pDocShell = mViewData->GetDocShell();
+    OUString aRowString1;
+    OUString aRowString2;
+    ScAddress aAddress;
+
+    SCTAB outTab = aOutputAddress.Tab();
+    SCCOL outCol = aOutputAddress.Col();
+
+    OUString aFormulaString;
+
+    for (size_t i = 0; i < aRangeList.size(); i++)
+    {
+        SCROW outRow = aOutputAddress.Row();
+        for (size_t j = 0; j < aRangeList.size(); j++)
+        {
+            if (j >= i)
+            {
+                aRangeList[i]->Format( aRowString1, SCR_ABS, mDocument, mAddressDetails );
+                aRangeList[j]->Format( aRowString2, SCR_ABS, mDocument, mAddressDetails );
+
+                aAddress = ScAddress(outCol, outRow, outTab);
+                aFormulaString = lclCovarTemplate.replaceAll(lclWildcardRow1, aRowString1);
+                aFormulaString = aFormulaString.replaceAll(lclWildcardRow2, aRowString2);
+                pDocShell->GetDocFunc().SetFormulaCell(aAddress, new ScFormulaCell(mDocument, aAddress, aFormulaString), true);
+            }
+            outRow++;
+        }
+        outCol++;
+    }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/CovarianceDialog.src b/sc/source/ui/StatisticsDialogs/CovarianceDialog.src
new file mode 100644
index 0000000..f3ca409
--- /dev/null
+++ b/sc/source/ui/StatisticsDialogs/CovarianceDialog.src
@@ -0,0 +1,19 @@
+/* -*- 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 "globstr.hrc"
+
+String STR_COVARIANCE_UNDO_NAME
+{
+    Text [ en-US ] = "Covariance";
+};
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx b/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx
index 7a01131..7d86870 100644
--- a/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx
+++ b/sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog.cxx
@@ -25,6 +25,34 @@
 
 #include "StatisticsInputOutputDialog.hxx"
 
+ScRangeList ScStatisticsInputOutputDialog::MakeColumnRangeList(SCTAB aTab, ScAddress aStart, ScAddress aEnd)
+{
+    ScRangeList aRangeList;
+    for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
+    {
+        ScRange aColumnRange (
+            ScAddress(inCol, aStart.Row(), aTab),
+            ScAddress(inCol, aEnd.Row(),   aTab) );
+
+        aRangeList.Append(aColumnRange);
+    }
+    return aRangeList;
+}
+
+ScRangeList ScStatisticsInputOutputDialog::MakeRowRangeList(SCTAB aTab, ScAddress aStart, ScAddress aEnd)
+{
+    ScRangeList aRangeList;
+    for (SCROW inRow = aStart.Row(); inRow <= aEnd.Row(); inRow++)
+    {
+        ScRange aRowRange (
+            ScAddress(aStart.Col(), inRow, aTab),
+            ScAddress(aEnd.Col(),   inRow, aTab) );
+
+        aRangeList.Append(aRowRange);
+    }
+    return aRangeList;
+}
+
 ScStatisticsInputOutputDialog::ScStatisticsInputOutputDialog(
                     SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
                     Window* pParent, ScViewData* pViewData, const OString& rID, const OUString& rUIXMLDescription ) :
diff --git a/sc/source/ui/app/scdll.cxx b/sc/source/ui/app/scdll.cxx
index e0b4489..c2ae6e5 100644
--- a/sc/source/ui/app/scdll.cxx
+++ b/sc/source/ui/app/scdll.cxx
@@ -271,6 +271,8 @@ void ScDLL::Init()
     ScSamplingDialogWrapper             ::RegisterChildWindow(false, pMod);
     ScDescriptiveStatisticsDialogWrapper::RegisterChildWindow(false, pMod);
     ScAnalysisOfVarianceDialogWrapper   ::RegisterChildWindow(false, pMod);
+    ScCorrelationDialogWrapper          ::RegisterChildWindow(false, pMod);
+    ScCovarianceDialogWrapper           ::RegisterChildWindow(false, pMod);
 
     // First docking Window for Calc
     ScFunctionChildWindow       ::RegisterChildWindow(false, pMod);
diff --git a/sc/source/ui/inc/CorrelationDialog.hxx b/sc/source/ui/inc/CorrelationDialog.hxx
new file mode 100644
index 0000000..f198175
--- /dev/null
+++ b/sc/source/ui/inc/CorrelationDialog.hxx
@@ -0,0 +1,43 @@
+/* -*- 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 CORRELATION_DIALOG_HXX
+#define CORRELATION_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 ScCorrelationDialog : public ScStatisticsInputOutputDialog
+{
+public:
+    ScCorrelationDialog(
+        SfxBindings* pB, SfxChildWindow* pCW,
+        Window* pParent, ScViewData* pViewData );
+
+    virtual ~ScCorrelationDialog();
+
+    virtual sal_Bool Close();
+
+protected:
+    virtual void CalculateInputAndWriteToOutput();
+    void WriteCorrelationFormulas(ScAddress aOutputAddress, ScRangeList aRangeList);
+};
+
+#endif
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/CovarianceDialog.hxx b/sc/source/ui/inc/CovarianceDialog.hxx
new file mode 100644
index 0000000..6aa9331
--- /dev/null
+++ b/sc/source/ui/inc/CovarianceDialog.hxx
@@ -0,0 +1,43 @@
+/* -*- 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 COVARIANCE_DIALOG_HXX
+#define COVARIANCE_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 ScCovarianceDialog : public ScStatisticsInputOutputDialog
+{
+public:
+    ScCovarianceDialog(
+        SfxBindings* pB, SfxChildWindow* pCW,
+        Window* pParent, ScViewData* pViewData );
+
+    virtual ~ScCovarianceDialog();
+
+    virtual sal_Bool Close();
+
+protected:
+    virtual void CalculateInputAndWriteToOutput();
+    void WriteCovarianceFormulas(ScAddress aOutputAddress, ScRangeList aRangeList);
+};
+
+#endif
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/StatisticsInputOutputDialog.hxx b/sc/source/ui/inc/StatisticsInputOutputDialog.hxx
index 4d0c0bb..a6ad9a7 100644
--- a/sc/source/ui/inc/StatisticsInputOutputDialog.hxx
+++ b/sc/source/ui/inc/StatisticsInputOutputDialog.hxx
@@ -52,6 +52,10 @@ protected:
     ScAddress::Details  mAddressDetails;
     ScAddress           mOutputAddress;
 
+    static ScRangeList MakeColumnRangeList(SCTAB aTab, ScAddress aStart, ScAddress aEnd);
+    static ScRangeList MakeRowRangeList(SCTAB aTab, ScAddress aStart, ScAddress aEnd);
+
+
 private:
     // Widgets
     PushButton*         mpButtonApply;
diff --git a/sc/source/ui/inc/reffact.hxx b/sc/source/ui/inc/reffact.hxx
index 08d191b..27c0d13 100644
--- a/sc/source/ui/inc/reffact.hxx
+++ b/sc/source/ui/inc/reffact.hxx
@@ -81,6 +81,19 @@ private:
     ScAnalysisOfVarianceDialogWrapper() SAL_DELETED_FUNCTION;
 };
 
+class ScCorrelationDialogWrapper :
+    public ChildWindowWrapper<SID_CORRELATION_DIALOG>
+{
+private:
+    ScCorrelationDialogWrapper() SAL_DELETED_FUNCTION;
+};
+
+class ScCovarianceDialogWrapper :
+    public ChildWindowWrapper<SID_COVARIANCE_DIALOG>
+{
+private:
+    ScCovarianceDialogWrapper() SAL_DELETED_FUNCTION;
+};
 
 class ScAcceptChgDlgWrapper: public SfxChildWindow
 {
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index 85a7506..239d1be 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -175,6 +175,8 @@ void ScCellShell::GetBlockState( SfxItemSet& rSet )
             case SID_SAMPLING_DIALOG:
             case SID_DESCRIPTIVE_STATISTICS_DIALOG:
             case SID_ANALYSIS_OF_VARIANCE_DIALOG:
+            case SID_CORRELATION_DIALOG:
+            case SID_COVARIANCE_DIALOG:
             {
                 bDisable = !bSimpleArea;
             }
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index e80266f..dc6cfa5 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -938,6 +938,24 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
             }
             break;
+        case SID_CORRELATION_DIALOG:
+            {
+                sal_uInt16 nId  = ScCorrelationDialogWrapper::GetChildWindowId();
+                SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
+                SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
+
+                pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
+            }
+            break;
+        case SID_COVARIANCE_DIALOG:
+            {
+                sal_uInt16 nId  = ScCovarianceDialogWrapper::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 02999e1..dde0afd 100644
--- a/sc/source/ui/view/tabvwsh.cxx
+++ b/sc/source/ui/view/tabvwsh.cxx
@@ -85,6 +85,9 @@ SFX_IMPL_INTERFACE(ScTabViewShell,SfxViewShell,ScResId(SCSTR_TABVIEWSHELL))
     SFX_CHILDWINDOW_REGISTRATION(ScSamplingDialogWrapper::GetChildWindowId());
     SFX_CHILDWINDOW_REGISTRATION(ScDescriptiveStatisticsDialogWrapper::GetChildWindowId());
     SFX_CHILDWINDOW_REGISTRATION(ScAnalysisOfVarianceDialogWrapper::GetChildWindowId());
+    SFX_CHILDWINDOW_REGISTRATION(ScCorrelationDialogWrapper::GetChildWindowId());
+    SFX_CHILDWINDOW_REGISTRATION(ScCovarianceDialogWrapper::GetChildWindowId());
+
 }
 
 SFX_IMPL_NAMED_VIEWFACTORY( ScTabViewShell, "Default" )
diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx
index a55d676..309a3e0 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -65,7 +65,8 @@
 #include "SamplingDialog.hxx"
 #include "DescriptiveStatisticsDialog.hxx"
 #include "AnalysisOfVarianceDialog.hxx"
-
+#include "CorrelationDialog.hxx"
+#include "CovarianceDialog.hxx"
 
 //------------------------------------------------------------------
 
@@ -341,6 +342,18 @@ SfxModelessDialog* ScTabViewShell::CreateRefDialog(
         }
         break;
 
+        case SID_CORRELATION_DIALOG:
+        {
+            pResult = new ScCorrelationDialog( pB, pCW, pParent, GetViewData() );
+        }
+        break;
+
+        case SID_COVARIANCE_DIALOG:
+        {
+            pResult = new ScCovarianceDialog( 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 a45cf12..d2bda57 100644
--- a/sc/uiconfig/scalc/menubar/menubar.xml
+++ b/sc/uiconfig/scalc/menubar/menubar.xml
@@ -485,6 +485,8 @@
                     <menu:menuitem menu:id=".uno:SamplingDialog"/>
                     <menu:menuitem menu:id=".uno:DescriptiveStatisticsDialog"/>
                     <menu:menuitem menu:id=".uno:AnalysisOfVarianceDialog"/>
+                    <menu:menuitem menu:id=".uno:CorrelationDialog"/>
+                    <menu:menuitem menu:id=".uno:CovarianceDialog"/>
                 </menu:menupopup>
             </menu:menu>
         </menu:menupopup>
commit fbd059fb60fc0afca20eec7ea26e0ae9beb384e4
Author: Tomaž Vajngerl <quikee at gmail.com>
Date:   Sat Jul 27 14:32:46 2013 +0200

    fdo#38144 Fix calculation of tick size in snapping to frame margin
    
    Change-Id: I36aa24880f28cb011e0b48e3b817c97a28475119

diff --git a/svx/source/dialog/svxruler.cxx b/svx/source/dialog/svxruler.cxx
index 41e377f..1c9021e 100644
--- a/svx/source/dialog/svxruler.cxx
+++ b/svx/source/dialog/svxruler.cxx
@@ -434,18 +434,21 @@ SvxRuler::~SvxRuler()
 
 long SvxRuler::MakePositionSticky(long aPosition, bool aSnapToFrameMargin) const
 {
-    long aLeftFramePosition = ConvertHPosPixel(GetLeftFrameMargin());
+    long aLeftFramePosition  = ConvertHPosPixel(GetLeftFrameMargin());
     long aRightFramePosition = ConvertHPosPixel(GetRightFrameMargin());
+
     long aTick = GetCurrentRulerUnit().nTick1;
+    long aTickPixel = pEditWin->LogicToPixel(Size(0, aTick), GetCurrentMapMode()).Height();
     long aHalfTick = aTick / 2;
+    long aHalfTickPixel = aTickPixel / 2;
 
     if (aSnapToFrameMargin)
     {
-        if (aPosition > aLeftFramePosition - aHalfTick && aPosition < aLeftFramePosition + aHalfTick)
+        if (aPosition > aLeftFramePosition - aHalfTickPixel && aPosition < aLeftFramePosition + aHalfTickPixel)
         {
             return aLeftFramePosition;
         }
-        else if (aPosition > aRightFramePosition - aHalfTick && aPosition < aRightFramePosition + aHalfTick)
+        else if (aPosition > aRightFramePosition - aHalfTickPixel && aPosition < aRightFramePosition + aHalfTickPixel)
         {
             return aRightFramePosition;
         }


More information about the Libreoffice-commits mailing list