summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-10-04 13:17:01 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-10-04 13:19:40 -0400
commitf3fae7d3c64db62568290f105d8404f037793945 (patch)
treebaf3eebb2c2671323894dac27ebe388f046d654f
parent6d5c352cb098daac139cb9c32df3420321eaaf3b (diff)
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
-rw-r--r--officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu2
-rw-r--r--sc/inc/column.hxx2
-rw-r--r--sc/inc/document.hxx5
-rw-r--r--sc/inc/sccommands.h1
-rw-r--r--sc/inc/table.hxx2
-rw-r--r--sc/source/core/data/column4.cxx24
-rw-r--r--sc/source/core/data/document10.cxx18
-rw-r--r--sc/source/core/data/table7.cxx12
-rw-r--r--sc/source/ui/view/cellsh.cxx6
-rw-r--r--sc/uiconfig/scalc/menubar/menubar.xml1
10 files changed, 72 insertions, 1 deletions
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index d81f35b32901..38e9dc2bad12 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 c694513ad491..9398d2471581 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 41fcffbd5f27..063c9f6d9a9f 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 3a2fb44382c1..8cfbd9978909 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 e0c6e2170b52..30df498c71d0 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 a577e7a87e5f..10b064277967 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 183e8e5d02e8..5689a68816b0 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 2104b6f983bc..36a22c643a23 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 8a03fc4e8847..2d44764ad2ce 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 f1df59509d7c..69102a562833 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"/>