Kaydet (Commit) f3fae7d3 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

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
üst 6d5c352c
......@@ -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>
......
......@@ -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;
......
......@@ -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,
......
......@@ -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
......
......@@ -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 );
......
......@@ -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: */
......@@ -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: */
......@@ -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: */
......@@ -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;
......
......@@ -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"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment