diff options
author | Justin Luth <jluth@mail.com> | 2024-03-12 13:16:52 -0400 |
---|---|---|
committer | Justin Luth <jluth@mail.com> | 2024-03-13 14:31:22 +0100 |
commit | 09d20ef6bd90d33a71b581d22d1312c5d26eb32b (patch) | |
tree | 2ab0a0b958b9af77a3325f9ea81a194922be4d09 /sc/source | |
parent | ef28f693351411c0d1651196b99e501acba7e7d5 (diff) |
tdf#123026: also use global config "RecalcOptimalRowHeightMode" for xlsx
24.8 commit 2d2974f22ab59ea7dab1aee778308c4f50ff5464 for tdf#124098
added a setting that prompts before recalculating optimal row height
on file open. I can't think of any reason why that shouldn't apply
to all formats. It defaults to "always - without asking".
XLSX started optimal row height on file open for tdf#123026
with 24.2 commit d15c4caabaa21e0efe3a08ffbe145390e802bab9.
So this patch just moves the code to a more accessible location,
and then uses it for the XLSX case too.
Change-Id: Ia0c672c3aec788857dea09ac88e4395dcf6c2242
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164721
Tested-by: Jenkins
Reviewed-by: Balazs Varga <balazs.varga.extern@allotropia.de>
Reviewed-by: Justin Luth <jluth@mail.com>
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/filter/oox/workbookhelper.cxx | 4 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.cxx | 73 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 56 | ||||
-rw-r--r-- | sc/source/ui/inc/docsh.hxx | 2 |
5 files changed, 63 insertions, 73 deletions
diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx index 2361122e0bfe..270e5aca1dc6 100644 --- a/sc/source/filter/oox/workbookhelper.cxx +++ b/sc/source/filter/oox/workbookhelper.cxx @@ -639,7 +639,9 @@ void WorkbookGlobals::finalize() mpDoc->EnableExecuteLink(true); // #i79826# enable updating automatic row height after loading the document mpDoc->UnlockAdjustHeight(); - mpDocShell->UpdateAllRowHeights(/*bOnlyUsedRows=*/true); + // check settings (potentially asking the user if optimal row height should be run now) + if (mpDocShell->GetRecalcRowHeightsMode()) // default is to always update + mpDocShell->UpdateAllRowHeights(/*bOnlyUsedRows=*/true); // #i76026# enable Undo after loading the document mpDoc->EnableUndo(true); diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx index 986aa69ebb7a..b59b644b5c4d 100644 --- a/sc/source/filter/xml/xmlimprt.cxx +++ b/sc/source/filter/xml/xmlimprt.cxx @@ -1206,76 +1206,6 @@ sal_Int32 ScXMLImport::GetRangeType(std::u16string_view sRangeType) return nRangeType; } -namespace { - -class MessageWithCheck : public weld::MessageDialogController -{ -private: - std::unique_ptr<weld::CheckButton> m_xWarningOnBox; -public: - MessageWithCheck(weld::Window *pParent, const OUString& rUIFile, const OUString& rDialogId) - : MessageDialogController(pParent, rUIFile, rDialogId, "ask") - , m_xWarningOnBox(m_xBuilder->weld_check_button("ask")) - { - } - bool get_active() const { return m_xWarningOnBox->get_active(); } - void hide_ask() const { m_xWarningOnBox->set_visible(false); }; -}; - -} - -bool ScXMLImport::GetRecalcRowHeightsMode() -{ - ScRecalcOptions nRecalcMode = - static_cast<ScRecalcOptions>(officecfg::Office::Calc::Formula::Load::RecalcOptimalRowHeightMode::get()); - - bool bHardRecalc = false; - switch (nRecalcMode) - { - case RECALC_ASK: - { - if (pDoc->IsUserInteractionEnabled()) - { - // Ask if the user wants to perform full re-calculation. - MessageWithCheck aQueryBox(ScDocShell::GetActiveDialogParent(), - "modules/scalc/ui/recalcquerydialog.ui", "RecalcQueryDialog"); - aQueryBox.set_primary_text(ScResId(STR_QUERY_OPT_ROW_HEIGHT_RECALC_ONLOAD)); - aQueryBox.set_default_response(RET_YES); - - if (officecfg::Office::Calc::Formula::Load::RecalcOptimalRowHeightMode::isReadOnly()) - aQueryBox.hide_ask(); - - bHardRecalc = aQueryBox.run() == RET_YES; - - if (aQueryBox.get_active()) - { - // Always perform selected action in the future. - std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create()); - officecfg::Office::Calc::Formula::Load::RecalcOptimalRowHeightMode::set( - bHardRecalc ? static_cast<sal_Int32>(RECALC_ALWAYS) : static_cast<sal_Int32>(RECALC_NEVER), batch); - - ScFormulaOptions aOpt = SC_MOD()->GetFormulaOptions(); - aOpt.SetReCalcOptiRowHeights(bHardRecalc ? RECALC_ALWAYS : RECALC_NEVER); - SC_MOD()->SetFormulaOptions(aOpt); - - batch->commit(); - } - } - } - break; - case RECALC_ALWAYS: - bHardRecalc = true; - break; - case RECALC_NEVER: - bHardRecalc = false; - break; - default: - SAL_WARN("sc", "unknown optimal row height recalc option!"); - } - - return bHardRecalc; -} - void ScXMLImport::SetLabelRanges() { if (maMyLabelRanges.empty()) @@ -1495,7 +1425,8 @@ void SAL_CALL ScXMLImport::endDocument() } // There are rows with optimal height which need to be updated - if (pDoc && !maRecalcRowRanges.empty() && GetRecalcRowHeightsMode()) + if (pDoc && !maRecalcRowRanges.empty() && pDoc->GetDocumentShell() + && pDoc->GetDocumentShell()->GetRecalcRowHeightsMode()) { bool bLockHeight = pDoc->IsAdjustHeightLocked(); if (bLockHeight) diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx index 546ccb97faf2..843e86536088 100644 --- a/sc/source/filter/xml/xmlimprt.hxx +++ b/sc/source/filter/xml/xmlimprt.hxx @@ -305,7 +305,6 @@ public: void SetRangeOverflowType(ErrCode nType); static sal_Int32 GetRangeType(std::u16string_view sRangeType); - bool GetRecalcRowHeightsMode(); void SetNamedRanges(); void SetSheetNamedRanges(); void SetLabelRanges(); diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 5f0cf927cd1d..857313f587b9 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -505,6 +505,62 @@ public: } +bool ScDocShell::GetRecalcRowHeightsMode() +{ + const ScRecalcOptions nRecalcMode = static_cast<ScRecalcOptions>( + officecfg::Office::Calc::Formula::Load::RecalcOptimalRowHeightMode::get()); + + bool bHardRecalc = false; + switch (nRecalcMode) + { + case RECALC_ASK: + { + if (m_pDocument->IsUserInteractionEnabled()) + { + // Ask if the user wants to perform full re-calculation. + MessageWithCheck aQueryBox(ScDocShell::GetActiveDialogParent(), + "modules/scalc/ui/recalcquerydialog.ui", + "RecalcQueryDialog"); + aQueryBox.set_primary_text(ScResId(STR_QUERY_OPT_ROW_HEIGHT_RECALC_ONLOAD)); + aQueryBox.set_default_response(RET_YES); + + if (officecfg::Office::Calc::Formula::Load::RecalcOptimalRowHeightMode::isReadOnly()) + aQueryBox.hide_ask(); + + bHardRecalc = aQueryBox.run() == RET_YES; + + if (aQueryBox.get_active()) + { + // Always perform selected action in the future. + std::shared_ptr<comphelper::ConfigurationChanges> batch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Calc::Formula::Load::RecalcOptimalRowHeightMode::set( + bHardRecalc ? static_cast<sal_Int32>(RECALC_ALWAYS) + : static_cast<sal_Int32>(RECALC_NEVER), + batch); + + ScFormulaOptions aOpt = SC_MOD()->GetFormulaOptions(); + aOpt.SetReCalcOptiRowHeights(bHardRecalc ? RECALC_ALWAYS : RECALC_NEVER); + SC_MOD()->SetFormulaOptions(aOpt); + + batch->commit(); + } + } + } + break; + case RECALC_ALWAYS: + bHardRecalc = true; + break; + case RECALC_NEVER: + bHardRecalc = false; + break; + default: + SAL_WARN("sc", "unknown optimal row height recalc option!"); + } + + return bHardRecalc; +} + bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const css::uno::Reference< css::embed::XStorage >& xStor ) { LoadMediumGuard aLoadGuard(m_pDocument.get()); diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx index 2f78bd16ef18..4cc4ceacfb11 100644 --- a/sc/source/ui/inc/docsh.hxx +++ b/sc/source/ui/inc/docsh.hxx @@ -266,6 +266,8 @@ public: void ErrorMessage(TranslateId pGlobStrId); bool IsEditable() const; + /// check config if on file-open optimal row heights should run, or if the user should be asked + SC_DLLPUBLIC bool GetRecalcRowHeightsMode(); bool AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab ); SC_DLLPUBLIC void UpdateAllRowHeights( const ScMarkData* pTabMark = nullptr ); SC_DLLPUBLIC void UpdateAllRowHeights(const bool bOnlyUsedRows); |