From f3fae7d3c64db62568290f105d8404f037793945 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Sat, 4 Oct 2014 13:17:01 -0400 Subject: 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 --- 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 + 9 files changed, 71 insertions(+) (limited to 'sc') 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& rCells ); + bool HasFormulaCell( SCROW nRow1, SCROW nRow2 ) const; + void CloneFormulaCell( const ScFormulaCell& rSrc, const std::vector& 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& 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& 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& 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 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 @@ + -- cgit