[Libreoffice-commits] core.git: officecfg/registry sc/inc sc/source sc/uiconfig

Kohei Yoshida kohei.yoshida at collabora.com
Sat Oct 4 10:15:51 PDT 2014


 officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu |    2 
 sc/inc/column.hxx                                                 |    2 
 sc/inc/document.hxx                                               |    5 ++
 sc/inc/sccommands.h                                               |    1 
 sc/inc/table.hxx                                                  |    2 
 sc/source/core/data/column4.cxx                                   |   24 ++++++++++
 sc/source/core/data/document10.cxx                                |   18 +++++++
 sc/source/core/data/table7.cxx                                    |   12 +++++
 sc/source/ui/view/cellsh.cxx                                      |    6 ++
 sc/uiconfig/scalc/menubar/menubar.xml                             |    1 
 10 files changed, 72 insertions(+), 1 deletion(-)

New commits:
commit f3fae7d3c64db62568290f105d8404f037793945
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sat Oct 4 13:17:01 2014 -0400

    Add menu entry for the "formula to value" feature.
    
    Not sure 100% if that's the best place for this.  Feel free to move it
    to a better place.
    
    Change-Id: Id66a92e1184e988bd71f7d845ea370b021c02c21

diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index d81f35b..38e9dc2 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
@@ -1711,7 +1711,7 @@
       </node>
       <node oor:name=".uno:ConvertFormulaToValue" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
-          <value xml:lang="en-US">Convert Formula to Value</value>
+          <value xml:lang="en-US">Formula to Value</value>
         </prop>
         <prop oor:name="Properties" oor:type="xs:int">
           <value>1</value>
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index c694513..9398d24 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -311,6 +311,8 @@ public:
 
     bool SetFormulaCells( SCROW nRow, std::vector<ScFormulaCell*>& rCells );
 
+    bool HasFormulaCell( SCROW nRow1, SCROW nRow2 ) const;
+
     void CloneFormulaCell( const ScFormulaCell& rSrc, const std::vector<sc::RowSpan>& rRanges );
 
     svl::SharedString GetSharedString( SCROW nRow ) const;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 41fcffb..063c9f6 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -866,6 +866,11 @@ public:
 
     bool SetFormulaCells( const ScAddress& rPos, std::vector<ScFormulaCell*>& rCells );
 
+    /**
+     * Check if there is at least one formula cell in specified range.
+     */
+    bool HasFormulaCell( const ScRange& rRange ) const;
+
     SC_DLLPUBLIC void InsertMatrixFormula(SCCOL nCol1, SCROW nRow1,
                                         SCCOL nCol2, SCROW nRow2,
                                         const ScMarkData& rMark,
diff --git a/sc/inc/sccommands.h b/sc/inc/sccommands.h
index 3a2fb44..8cfbd99 100644
--- a/sc/inc/sccommands.h
+++ b/sc/inc/sccommands.h
@@ -105,6 +105,7 @@
 #define CMD_FID_TAB_MENU_SET_TAB_BG_COLOR           ".uno:SetTabBgColor"
 #define CMD_FID_TAB_SET_TAB_BG_COLOR                ".uno:TabBgColor"
 #define CMD_SID_MANAGE_XML_SOURCE                   ".uno:ManageXMLSource"
+#define CMD_SID_CONVERT_FORMULA_TO_VALUE            ".uno:ConvertFormulaToValue"
 
 #endif
 
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index e0c6e21..30df498 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -351,6 +351,8 @@ public:
 
     bool SetFormulaCells( SCCOL nCol, SCROW nRow, std::vector<ScFormulaCell*>& rCells );
 
+    bool HasFormulaCell( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const;
+
     svl::SharedString GetSharedString( SCCOL nCol, SCROW nRow ) const;
 
     void        SetValue( SCCOL nCol, SCROW nRow, const double& rVal );
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index a577e7a..10b0642 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -1107,4 +1107,28 @@ void ScColumn::CollectListeners( std::vector<SvtListener*>& rListeners, SCROW nR
     sc::ProcessBroadcaster(maBroadcasters.begin(), maBroadcasters, nRow1, nRow2, aFunc);
 }
 
+namespace {
+
+struct FindAnyFormula
+{
+    bool operator() ( size_t /*nRow*/, const ScFormulaCell* /*pCell*/ ) const
+    {
+        return true;
+    }
+};
+
+}
+
+bool ScColumn::HasFormulaCell( SCROW nRow1, SCROW nRow2 ) const
+{
+    if (nRow2 < nRow1 || !ValidRow(nRow1) || !ValidRow(nRow2))
+        return false;
+
+    FindAnyFormula aFunc;
+    std::pair<sc::CellStoreType::const_iterator, size_t> aRet =
+        sc::FindFormula(maCells, nRow1, nRow2, aFunc);
+
+    return aRet.first != maCells.end();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx
index 183e8e5..5689a68 100644
--- a/sc/source/core/data/document10.cxx
+++ b/sc/source/core/data/document10.cxx
@@ -435,4 +435,22 @@ void ScDocument::CollectAllAreaListeners(
         rListener.push_back(it->mpListener);
 }
 
+bool ScDocument::HasFormulaCell( const ScRange& rRange ) const
+{
+    if (!rRange.IsValid())
+        return false;
+
+    for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab)
+    {
+        const ScTable* pTab = FetchTable(nTab);
+        if (!pTab)
+            continue;
+
+        if (pTab->HasFormulaCell(rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row()))
+            return true;
+    }
+
+    return false;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/table7.cxx b/sc/source/core/data/table7.cxx
index 2104b6f..36a22c6 100644
--- a/sc/source/core/data/table7.cxx
+++ b/sc/source/core/data/table7.cxx
@@ -180,4 +180,16 @@ void ScTable::CollectListeners(
         aCol[nCol].CollectListeners(rListeners, nRow1, nRow2);
 }
 
+bool ScTable::HasFormulaCell( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 ) const
+{
+    if (nCol2 < nCol1 || !ValidCol(nCol1) || !ValidCol(nCol2))
+        return false;
+
+    for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
+        if (aCol[nCol].HasFormulaCell(nRow1, nRow2))
+            return true;
+
+    return false;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index 8a03fc4..2d44764 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -254,6 +254,12 @@ void ScCellShell::GetBlockState( SfxItemSet& rSet )
             case SID_TRANSLITERATE_KATAGANA:
                 ScViewUtil::HideDisabledSlot( rSet, GetViewData()->GetBindings(), nWhich );
             break;
+            case SID_CONVERT_FORMULA_TO_VALUE:
+            {
+                // Check and see if the marked range has at least one formula cell.
+                bDisable = !pDoc->HasFormulaCell(aMarkRange);
+            }
+            break;
         }
         if (!bDisable && bNeedEdit && !bEditable)
             bDisable = true;
diff --git a/sc/uiconfig/scalc/menubar/menubar.xml b/sc/uiconfig/scalc/menubar/menubar.xml
index f1df595..69102a5 100644
--- a/sc/uiconfig/scalc/menubar/menubar.xml
+++ b/sc/uiconfig/scalc/menubar/menubar.xml
@@ -413,6 +413,7 @@
             <menu:menu menu:id=".uno:CellContentsMenu">
                 <menu:menupopup>
                     <menu:menuitem menu:id=".uno:Calculate"/>
+                    <menu:menuitem menu:id=".uno:ConvertFormulaToValue"/>
                     <menu:menuitem menu:id=".uno:AutomaticCalculation"/>
                     <menu:menuseparator/>
                     <menu:menuitem menu:id=".uno:AutoComplete"/>


More information about the Libreoffice-commits mailing list