From a8cfe77dd76547caca157fa4cb2edecfe2f7406d Mon Sep 17 00:00:00 2001 From: Karthik Date: Wed, 20 Aug 2025 16:02:25 +0530 Subject: [PATCH] Calc: Adapt 'SvxAutoFormat' Adapt 'SvxAutoFormat' and retire Calc specific 'AutoFormat' dialog and preview Change-Id: I7d1146ba3612c2bd528a4f0daa5485a9c0296dea Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190026 Tested-by: Heiko Tietze Tested-by: Jenkins Reviewed-by: Heiko Tietze --- sc/CppunitTest_sc_autoformatsobj.mk | 6 + sc/Library_sc.mk | 1 - sc/Library_scui.mk | 1 - sc/Module_sc.mk | 1 - sc/Package_res_xml.mk | 1 + sc/inc/autoform.hxx | 198 +-- sc/inc/global.hxx | 1 + sc/inc/pch/precompiled_scui.hxx | 1 - sc/inc/scabstdlg.hxx | 4 - sc/qa/extras/macros-test.cxx | 36 +- sc/qa/extras/scautoformatobj.cxx | 5 +- sc/qa/extras/scautoformatsobj.cxx | 4 +- sc/qa/uitest/calc_tests6/autoFormat.py | 5 - .../tdf91726_autoformat_existing_name.py | 10 +- sc/res/xml/tablestyles.xml | 1081 ++++++++++++++++ sc/source/core/data/global.cxx | 7 +- sc/source/core/data/poolcach.cxx | 34 +- sc/source/core/data/table4.cxx | 284 ++--- sc/source/core/tool/autoform.cxx | 1096 +++++------------ sc/source/ui/attrdlg/scdlgfact.cxx | 21 - sc/source/ui/attrdlg/scdlgfact.hxx | 4 - sc/source/ui/docshell/docfunc.cxx | 3 +- sc/source/ui/inc/autofmt.hxx | 92 -- sc/source/ui/inc/scuiautofmt.hxx | 80 -- sc/source/ui/miscdlgs/autofmt.cxx | 532 -------- sc/source/ui/miscdlgs/scuiautofmt.cxx | 389 ------ sc/source/ui/unoobj/afmtuno.cxx | 113 +- sc/source/ui/unoobj/cellsuno.cxx | 15 +- sc/source/ui/view/cellsh3.cxx | 30 +- solenv/clang-format/excludelist | 3 - 30 files changed, 1653 insertions(+), 2405 deletions(-) create mode 100644 sc/res/xml/tablestyles.xml delete mode 100644 sc/source/ui/inc/autofmt.hxx delete mode 100644 sc/source/ui/inc/scuiautofmt.hxx delete mode 100644 sc/source/ui/miscdlgs/autofmt.cxx delete mode 100644 sc/source/ui/miscdlgs/scuiautofmt.cxx diff --git a/sc/CppunitTest_sc_autoformatsobj.mk b/sc/CppunitTest_sc_autoformatsobj.mk index 7b8f48c3dcbc..a0bc220f509d 100644 --- a/sc/CppunitTest_sc_autoformatsobj.mk +++ b/sc/CppunitTest_sc_autoformatsobj.mk @@ -11,4 +11,10 @@ $(eval $(call sc_unoapi_common,autoformatsobj)) +.PHONY: restore-default-autoformats +restore-default-autoformats: + -cp "sc/res/xml/tablestyles.xml" "$(INSTROOT)/$(LIBO_SHARE_FOLDER)/calc/tablestyles.xml" + +$(call gb_CppunitTest_get_target,sc_autoformatsobj): restore-default-autoformats + # vim: set noet sw=4 ts=4: diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index e46cbfe00b57..c188dfd43212 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -504,7 +504,6 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/ui/formdlg/formula \ sc/source/ui/miscdlgs/acredlin \ sc/source/ui/miscdlgs/anyrefdg \ - sc/source/ui/miscdlgs/autofmt \ sc/source/ui/miscdlgs/conflictsdlg \ sc/source/ui/miscdlgs/crnrdlg \ sc/source/ui/miscdlgs/datastreamdlg \ diff --git a/sc/Library_scui.mk b/sc/Library_scui.mk index a71140b9803b..ca2b88187ddc 100644 --- a/sc/Library_scui.mk +++ b/sc/Library_scui.mk @@ -107,7 +107,6 @@ $(eval $(call gb_Library_add_exception_objects,scui,\ sc/source/ui/miscdlgs/mtrindlg \ sc/source/ui/miscdlgs/mvtabdlg \ sc/source/ui/miscdlgs/namecrea \ - sc/source/ui/miscdlgs/scuiautofmt \ sc/source/ui/miscdlgs/shtabdlg \ sc/source/ui/miscdlgs/strindlg \ sc/source/ui/miscdlgs/tabbgcolordlg \ diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk index 23660453f3e3..f7ff2b0ed80a 100644 --- a/sc/Module_sc.mk +++ b/sc/Module_sc.mk @@ -138,7 +138,6 @@ $(eval $(call gb_Module_add_slowcheck_targets,sc, \ CppunitTest_sc_arealinkobj \ CppunitTest_sc_arealinksobj \ CppunitTest_sc_autoformatobj \ - CppunitTest_sc_autoformatsobj \ CppunitTest_sc_cellcursorobj \ CppunitTest_sc_cellfieldsobj \ CppunitTest_sc_cellformatsenumeration \ diff --git a/sc/Package_res_xml.mk b/sc/Package_res_xml.mk index 383e8d598781..463842970b83 100644 --- a/sc/Package_res_xml.mk +++ b/sc/Package_res_xml.mk @@ -11,6 +11,7 @@ $(eval $(call gb_Package_Package,sc_res_xml,$(SRCDIR)/sc/res/xml)) $(eval $(call gb_Package_add_files,sc_res_xml,$(LIBO_SHARE_FOLDER)/calc,\ styles.xml \ + tablestyles.xml \ )) # vim: set noet sw=4 ts=4: diff --git a/sc/inc/autoform.hxx b/sc/inc/autoform.hxx index 7581d8a64e2e..6db6dc2af3cf 100644 --- a/sc/inc/autoform.hxx +++ b/sc/inc/autoform.hxx @@ -19,198 +19,72 @@ #pragma once -/************************************************************************* -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - The structure of auto formatting should not be changed. It is used - by various code of Writer and Calc. If a change is necessary, the - source code of both applications must be changed! - -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -**************************************************************************/ - -#include -#include - +#include +#include +#include #include "scdllapi.h" -#include "zforauto.hxx" #include #include -#include -#include +#include "document.hxx" -class SfxItemSet; -class ScDocument; - -/** -A binary blob of writer-specific data. This data typically consists of types that are -unavailable to Calc (e.g. SwFmtVertOrient), or that Calc doesn't care about. - -@remarks Note that in autoformat versions prior to AUTOFORMAT_DATA_ID_31005, Calc -logic handled and stored several writer-specific items (such as ScAutoFormatDataField::aAdjust). -That logic was preserved. From _31005 onward, writer-specific data should be handled by -blobs to avoid needlessly complicating the Calc logic. -*/ -struct AutoFormatSwBlob +class ScAutoFormatDataField : public SvxAutoFormatDataField { - std::unique_ptr pData; - std::size_t size; - - AutoFormatSwBlob() : size(0) - { - } - AutoFormatSwBlob(const AutoFormatSwBlob&) = delete; - const AutoFormatSwBlob& operator=(const AutoFormatSwBlob&) = delete; - - void Reset() - { - pData.reset(); - size = 0; - } -}; - -/// Struct with version numbers of the Items -struct ScAfVersions : public AutoFormatVersions -{ -private: - AutoFormatSwBlob swVersions; - -public: - ScAfVersions(); - - void Load( SvStream& rStream, sal_uInt16 nVer ); - void Write(SvStream& rStream, sal_uInt16 fileVersion); -}; - -/// Contains all items for one cell of a table autoformat. -class ScAutoFormatDataField : public AutoFormatBase -{ -private: - AutoFormatSwBlob m_swFields; - - // number format - ScNumFormatAbbrev aNumFormat; - public: ScAutoFormatDataField(); - ScAutoFormatDataField( const ScAutoFormatDataField& rCopy ); + ScAutoFormatDataField(const ScAutoFormatDataField& rCopy); + ScAutoFormatDataField(const SvxAutoFormatDataField& rCopy); ~ScAutoFormatDataField(); - // block assignment operator - ScAutoFormatDataField& operator=(const ScAutoFormatDataField& rRef) = delete; - - // number format - const ScNumFormatAbbrev& GetNumFormat() const { return aNumFormat; } - - // number format - void SetNumFormat( const ScNumFormatAbbrev& rNumFormat ) { aNumFormat = rNumFormat; } - - bool Load( SvStream& rStream, const ScAfVersions& rVersions, sal_uInt16 nVer ); - bool Save( SvStream& rStream, sal_uInt16 fileVersion ); }; -class SAL_DLLPUBLIC_RTTI ScAutoFormatData +class SAL_DLLPUBLIC_RTTI ScAutoFormatData : public SvxAutoFormatData { private: - OUString aName; - sal_uInt16 nStrResId; - // common flags of Calc and Writer - bool bIncludeFont : 1; - bool bIncludeJustify : 1; - bool bIncludeFrame : 1; - bool bIncludeBackground : 1; - - // Calc specific flags - bool bIncludeValueFormat : 1; - bool bIncludeWidthHeight : 1; - - // Writer-specific data - AutoFormatSwBlob m_swFields; - - std::array,16> ppDataField; - - SAL_DLLPRIVATE ScAutoFormatDataField& GetField( sal_uInt16 nIndex ); - SAL_DLLPRIVATE const ScAutoFormatDataField& GetField( sal_uInt16 nIndex ) const; + std::array, ELEMENT_COUNT> mpDataField; public: ScAutoFormatData(); - SC_DLLPUBLIC ScAutoFormatData( const ScAutoFormatData& rData ); - SC_DLLPUBLIC ~ScAutoFormatData(); + SC_DLLPUBLIC ScAutoFormatData(const ScAutoFormatData& rData); + SC_DLLPUBLIC ScAutoFormatData(const SvxAutoFormatData& rData); - void SetName( const OUString& rName ) { aName = rName; nStrResId = USHRT_MAX; } - const OUString& GetName() const { return aName; } + ScAutoFormatDataField* GetField(size_t nIndex) override; + const ScAutoFormatDataField* GetField(size_t nIndex) const override; + bool SetField(size_t nIndex, const SvxAutoFormatDataField& aField) override; + SvxAutoFormatData* MakeCopy() const override { return new ScAutoFormatData(*this); }; + SvxAutoFormatDataField* GetDefaultField() const override { return new ScAutoFormatDataField; }; - bool GetIncludeValueFormat() const { return bIncludeValueFormat; } - bool GetIncludeFont() const { return bIncludeFont; } - bool GetIncludeJustify() const { return bIncludeJustify; } - bool GetIncludeFrame() const { return bIncludeFrame; } - bool GetIncludeBackground() const { return bIncludeBackground; } - bool GetIncludeWidthHeight() const { return bIncludeWidthHeight; } - - void SetIncludeValueFormat( bool bValueFormat ) { bIncludeValueFormat = bValueFormat; } - void SetIncludeFont( bool bFont ) { bIncludeFont = bFont; } - void SetIncludeJustify( bool bJustify ) { bIncludeJustify = bJustify; } - void SetIncludeFrame( bool bFrame ) { bIncludeFrame = bFrame; } - void SetIncludeBackground( bool bBackground ) { bIncludeBackground = bBackground; } - void SetIncludeWidthHeight( bool bWidthHeight ) { bIncludeWidthHeight = bWidthHeight; } - - const SfxPoolItem* GetItem( sal_uInt16 nIndex, sal_uInt16 nWhich ) const; - template const T* GetItem( sal_uInt16 nIndex, TypedWhichId nWhich ) const + const SfxPoolItem* GetItem(sal_uInt8 nIndex, sal_uInt16 nWhich) const; + template const T* GetItem(sal_uInt8 nIndex, TypedWhichId nWhich) const { return static_cast(GetItem(nIndex, sal_uInt16(nWhich))); } - void PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem ); - void CopyItem( sal_uInt16 nToIndex, sal_uInt16 nFromIndex, sal_uInt16 nWhich ); + void PutItem(size_t nIndex, const SfxPoolItem& rItem); - const ScNumFormatAbbrev& GetNumFormat( sal_uInt16 nIndex ) const; - - bool HasSameData( sal_uInt16 nIndex1, sal_uInt16 nIndex2 ) const; - - void FillToItemSet( sal_uInt16 nIndex, SfxItemSet& rItemSet, const ScDocument& rDoc ) const; - void GetFromItemSet( sal_uInt16 nIndex, const SfxItemSet& rItemSet, const ScNumFormatAbbrev& rNumFormat ); - - bool Load( SvStream& rStream, const ScAfVersions& rVersions ); - bool Save( SvStream& rStream, sal_uInt16 fileVersion ); + void CopyItem(size_t nToIndex, size_t nFromIndex, sal_uInt16 nWhich); + void FillToItemSet(size_t nIndex, SfxItemSet& rItemSet) const; + void GetFromItemSet(size_t nIndex, const SfxItemSet& rItemSet); }; -struct DefaultFirstEntry { - bool operator() (const OUString& left, const OUString& right) const; -}; - -class SAL_DLLPUBLIC_RTTI ScAutoFormat +class SAL_DLLPUBLIC_RTTI ScAutoFormat : public SvxAutoFormat { - typedef std::map, DefaultFirstEntry> MapType; - MapType m_Data; - bool mbSaveLater; - ScAfVersions m_aVersions; - - ScAutoFormat(const ScAutoFormat&) = delete; - const ScAutoFormat operator=(const ScAutoFormat&) = delete; +private: + struct Impl; + std::unique_ptr mpImpl; public: - typedef MapType::const_iterator const_iterator; - typedef MapType::iterator iterator; - ScAutoFormat(); - void Load(); - SC_DLLPUBLIC bool Save(); + ~ScAutoFormat(); - void SetSaveLater( bool bSet ); - bool IsSaveLater() const { return mbSaveLater; } - - const ScAutoFormatData* findByIndex(size_t nIndex) const; - SC_DLLPUBLIC ScAutoFormatData* findByIndex(size_t nIndex); - SC_DLLPUBLIC iterator find(const OUString& rName); - - SC_DLLPUBLIC iterator insert(std::unique_ptr pNew); - SC_DLLPUBLIC void erase(const iterator& it); - - SC_DLLPUBLIC size_t size() const; - const_iterator begin() const; - const_iterator end() const; - SC_DLLPUBLIC iterator begin(); - SC_DLLPUBLIC iterator end(); + const ScAutoFormatData* GetData(size_t nIndex) const override; + ScAutoFormatData* GetData(size_t nIndex) override; + bool InsertAutoFormat(SvxAutoFormatData* pFormat) override; + ScAutoFormatData* ReleaseAutoFormat(const OUString& rName) override; + ScAutoFormatData* FindAutoFormat(const OUString& rName) const override; + const ScAutoFormatData* GetResolvedStyle(const SvxAutoFormatData* pData) const override; + SvxAutoFormatData* GetDefaultData() override { return new ScAutoFormatData();}; + SvxAutoFormatDataField* GetDefaultField() override { return new ScAutoFormatDataField; }; + size_t size() const override; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx index 4f53eede8bb8..ee0f8fd7bcae 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -587,6 +587,7 @@ public: SC_DLLPUBLIC static void SetSearchItem( const SvxSearchItem& rNew ); SC_DLLPUBLIC static ScAutoFormat* GetAutoFormat(); SC_DLLPUBLIC static ScAutoFormat* GetOrCreateAutoFormat(); + SC_DLLPUBLIC static void ResetAutoFormat(); static void ClearAutoFormat(); //BugId 54209 static LegacyFuncCollection* GetLegacyFuncCollection(); SC_DLLPUBLIC static ScUnoAddInCollection* GetAddInCollection(); diff --git a/sc/inc/pch/precompiled_scui.hxx b/sc/inc/pch/precompiled_scui.hxx index 4bd501449f5e..502a197c17df 100644 --- a/sc/inc/pch/precompiled_scui.hxx +++ b/sc/inc/pch/precompiled_scui.hxx @@ -173,7 +173,6 @@ #include #include #include -#include #include #include #include diff --git a/sc/inc/scabstdlg.hxx b/sc/inc/scabstdlg.hxx index d3a4914f5d5f..456b627de6c8 100644 --- a/sc/inc/scabstdlg.hxx +++ b/sc/inc/scabstdlg.hxx @@ -421,10 +421,6 @@ public: virtual VclPtr CreateScTextImportOptionsDlg(weld::Window* pParent) = 0; - virtual VclPtr CreateScAutoFormatDlg(weld::Window* pParent, - ScAutoFormat* pAutoFormat, - const ScAutoFormatData* pSelFormatData, - ScViewData& rViewData) = 0; virtual VclPtr CreateScColRowLabelDlg (weld::Window* pParent, bool bCol, bool bRow) = 0; diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index cac7ad93b542..f668f9cad3c5 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -7,6 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include #include #include #include @@ -719,7 +720,7 @@ CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf107572) u"TestModule"_ustr, uno::Any( u"Function Main\n" - " thisComponent.Sheets(0).getCellRangeByName(\"A1:F14\").autoformat(\"Default\")\n" + " thisComponent.Sheets(0).getCellRangeByName(\"A1:F14\").autoformat(\"Default Style\")\n" "End Function\n"_ustr)); // Without the fix in place, this test would have crashed @@ -727,29 +728,20 @@ CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf107572) ScDocument* pDoc = getScDoc(); - //Check the autoformat has been applied - for (SCCOL i = 0; i < 5; ++i) + SCCOL startCol = 0, endCol = 4; + SCROW startRow = 0, endRow = 12; + + // Check autoformat has benn applied + for (SCCOL col = startCol; col <= endCol; ++col) { - const ScPatternAttr* pAttr = pDoc->GetPattern(i, 0, 0); - const SvxBrushItem& rBackground = pAttr->GetItem(ATTR_BACKGROUND); - const Color& rColor = rBackground.GetColor(); + for (SCROW row = startRow; row <= endRow; ++row) + { + const ScPatternAttr* pAttr = pDoc->GetPattern(col, row, 0); + const SvxBoxItem& rBorder = pAttr->GetItem(ATTR_BORDER); - CPPUNIT_ASSERT_EQUAL(COL_BLUE, rColor); - } - - for (SCROW i = 1; i < 13; ++i) - { - const ScPatternAttr* pAttr = pDoc->GetPattern(0, i, 0); - const SvxBrushItem& rBackground = pAttr->GetItem(ATTR_BACKGROUND); - const Color& rColor = rBackground.GetColor(); - - CPPUNIT_ASSERT_EQUAL(Color(0x4d, 0x4d, 0x4d), rColor); - - const ScPatternAttr* pAttr2 = pDoc->GetPattern(5, i, 0); - const SvxBrushItem& rBackground2 = pAttr2->GetItem(ATTR_BACKGROUND); - const Color& rColor2 = rBackground2.GetColor(); - - CPPUNIT_ASSERT_EQUAL(COL_GRAY3, rColor2); + CPPUNIT_ASSERT_EQUAL(COL_BLACK, rBorder.GetTop()->GetColor()); + CPPUNIT_ASSERT_EQUAL(COL_BLACK, rBorder.GetLeft()->GetColor()); + } } } diff --git a/sc/qa/extras/scautoformatobj.cxx b/sc/qa/extras/scautoformatobj.cxx index 57f9fcb3b875..ed5ffb8b272d 100644 --- a/sc/qa/extras/scautoformatobj.cxx +++ b/sc/qa/extras/scautoformatobj.cxx @@ -83,7 +83,7 @@ ScAutoFormatObj::ScAutoFormatObj() : UnoApiTest(u"/sc/qa/extras/testdocuments"_ustr) , XElementAccess(cppu::UnoType::get()) , XIndexAccess(16) - , XNamed(u"Default"_ustr) + , XNamed(u"Simple List Shaded"_ustr) // The last table style in 'tablestyles.xml' , XServiceInfo(u"ScAutoFormatObj"_ustr, u"com.sun.star.sheet.TableAutoFormat"_ustr) { } @@ -96,8 +96,7 @@ uno::Reference ScAutoFormatObj::init() uno::Reference xIA( xMSF->createInstance(u"com.sun.star.sheet.TableAutoFormats"_ustr), uno::UNO_QUERY_THROW); - uno::Reference xTableAutoFormat(xIA->getByIndex(xIA->getCount() - 1), - uno::UNO_QUERY_THROW); + uno::Reference xTableAutoFormat(xIA->getByIndex(10), uno::UNO_QUERY_THROW); return xTableAutoFormat; } diff --git a/sc/qa/extras/scautoformatsobj.cxx b/sc/qa/extras/scautoformatsobj.cxx index d000ee4a51ab..6f266a970e8d 100644 --- a/sc/qa/extras/scautoformatsobj.cxx +++ b/sc/qa/extras/scautoformatsobj.cxx @@ -83,8 +83,8 @@ public: ScAutoFormatsObj::ScAutoFormatsObj() : UnoApiTest(u"/sc/qa/extras/testdocuments"_ustr) , XElementAccess(cppu::UnoType::get()) - , XIndexAccess(2) - , XNameAccess(u"Default"_ustr) + , XIndexAccess(12) // There are 11 table styles by default, so (11 + 1) + , XNameAccess(u"Default Style"_ustr) , XNameContainer(u"ScAutoFormatsObj"_ustr) , XNameReplace(u"ScAutoFormatsObj"_ustr) , XServiceInfo(u"stardiv.StarCalc.ScAutoFormatsObj"_ustr, diff --git a/sc/qa/uitest/calc_tests6/autoFormat.py b/sc/qa/uitest/calc_tests6/autoFormat.py index e5ff72f073ad..0af11863cade 100644 --- a/sc/qa/uitest/calc_tests6/autoFormat.py +++ b/sc/qa/uitest/calc_tests6/autoFormat.py @@ -27,7 +27,6 @@ class autoFormat(UITestCase): fontcb = xDialog.getChild("fontcb") patterncb = xDialog.getChild("patterncb") alignmentcb = xDialog.getChild("alignmentcb") - autofitcb = xDialog.getChild("autofitcb") entry = formatlb.getChild("7") #Financial entry.executeAction("SELECT", tuple()) @@ -36,7 +35,6 @@ class autoFormat(UITestCase): fontcb.executeAction("CLICK", tuple()) patterncb.executeAction("CLICK", tuple()) alignmentcb.executeAction("CLICK", tuple()) - autofitcb.executeAction("CLICK", tuple()) #verify @@ -48,7 +46,6 @@ class autoFormat(UITestCase): fontcb = xDialog.getChild("fontcb") patterncb = xDialog.getChild("patterncb") alignmentcb = xDialog.getChild("alignmentcb") - autofitcb = xDialog.getChild("autofitcb") entry = formatlb.getChild("7") #Financial entry.executeAction("SELECT", tuple()) @@ -57,13 +54,11 @@ class autoFormat(UITestCase): self.assertEqual(get_state_as_dict(fontcb)["Selected"], "false") self.assertEqual(get_state_as_dict(patterncb)["Selected"], "false") self.assertEqual(get_state_as_dict(alignmentcb)["Selected"], "false") - self.assertEqual(get_state_as_dict(autofitcb)["Selected"], "false") numformatcb.executeAction("CLICK", tuple()) bordercb.executeAction("CLICK", tuple()) fontcb.executeAction("CLICK", tuple()) patterncb.executeAction("CLICK", tuple()) alignmentcb.executeAction("CLICK", tuple()) - autofitcb.executeAction("CLICK", tuple()) # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sc/qa/uitest/calc_tests6/tdf91726_autoformat_existing_name.py b/sc/qa/uitest/calc_tests6/tdf91726_autoformat_existing_name.py index 4c6ff5b0f00f..882928339ec0 100644 --- a/sc/qa/uitest/calc_tests6/tdf91726_autoformat_existing_name.py +++ b/sc/qa/uitest/calc_tests6/tdf91726_autoformat_existing_name.py @@ -21,13 +21,13 @@ class tdf91726(UITestCase): #AutoFormat Styles with self.ui_test.execute_dialog_through_command(".uno:AutoFormat", close_button="") as xDialog: #add new style "Default" - xadd = xDialog.getChild("add") + xadd = xDialog.getChild("rename") # Use empty close_button to open consecutive dialogs with self.ui_test.execute_blocking_action( xadd.executeAction, args=('CLICK', ()), close_button="") as dialog: - nameEntry = dialog.getChild("name_entry") - nameEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"Default"})) + nameEntry = dialog.getChild("edit") + nameEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"Academic"})) xOKBtn = dialog.getChild("ok") with self.ui_test.execute_blocking_action( @@ -39,9 +39,9 @@ class tdf91726(UITestCase): with self.ui_test.execute_blocking_action( xOKBtn2.executeAction, args=('CLICK', ()), close_button="cancel") as dialog3: - nameEntry = dialog3.getChild("name_entry") + nameEntry = dialog3.getChild("edit") #back to name dialog, LO should not crash - self.assertEqual(get_state_as_dict(nameEntry)["Text"], "Default") + self.assertEqual(get_state_as_dict(nameEntry)["Text"], "Default Style") xCanceltn = xDialog.getChild("cancel") self.ui_test.close_dialog_through_button(xCanceltn) diff --git a/sc/res/xml/tablestyles.xml b/sc/res/xml/tablestyles.xml new file mode 100644 index 000000000000..e3926532180f --- /dev/null +++ b/sc/res/xml/tablestyles.xml @@ -0,0 +1,1081 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx index b5aefde17c98..8e150994fbbe 100644 --- a/sc/source/core/data/global.cxx +++ b/sc/source/core/data/global.cxx @@ -252,10 +252,6 @@ void ScGlobal::ClearAutoFormat() assert(!bThreadedGroupCalcInProgress); if (xAutoFormat) { - // When modified via StarOne then only the SaveLater flag is set and no saving is done. - // If the flag is set then save now. - if (xAutoFormat->IsSaveLater()) - xAutoFormat->Save(); xAutoFormat.reset(); } } @@ -271,12 +267,13 @@ ScAutoFormat* ScGlobal::GetOrCreateAutoFormat() if ( !xAutoFormat ) { xAutoFormat.reset(new ScAutoFormat); - xAutoFormat->Load(); } return xAutoFormat.get(); } +void ScGlobal::ResetAutoFormat() { xAutoFormat.reset(new ScAutoFormat); } + LegacyFuncCollection* ScGlobal::GetLegacyFuncCollection() { return comphelper::doubleCheckedInit( pLegacyFuncCollection, []() { return new LegacyFuncCollection(); }); diff --git a/sc/source/core/data/poolcach.cxx b/sc/source/core/data/poolcach.cxx index 4107dd89f180..e82ec1d7d7c6 100644 --- a/sc/source/core/data/poolcach.cxx +++ b/sc/source/core/data/poolcach.cxx @@ -18,6 +18,7 @@ */ +#include #include #include #include @@ -68,7 +69,38 @@ const CellAttributeHolder& ScItemPoolCache::ApplyTo(const CellAttributeHolder& r } else { - pNewItem->GetItemSetWritable().Put(*pSetToPut); + // We preserve original cell's border formatting + if (pSetToPut->GetItemState(ATTR_BORDER, false) == SfxItemState::SET) + { + if (const SvxBoxItem* pOldBox = pAttr->GetItemSet().GetItemIfSet(ATTR_BORDER)) + { + SvxBoxItem aNewBox(pSetToPut->Get(ATTR_BORDER)); + if (!aNewBox.GetTop()) + aNewBox.SetLine(pOldBox->GetTop(), SvxBoxItemLine::TOP); + if (!aNewBox.GetBottom()) + aNewBox.SetLine(pOldBox->GetBottom(), SvxBoxItemLine::BOTTOM); + if (!aNewBox.GetLeft()) + aNewBox.SetLine(pOldBox->GetLeft(), SvxBoxItemLine::LEFT); + if (!aNewBox.GetRight()) + aNewBox.SetLine(pOldBox->GetRight(), SvxBoxItemLine::RIGHT); + if (!aNewBox.GetDistance(SvxBoxItemLine::RIGHT)) + aNewBox.SetAllDistances(pOldBox->GetDistance(SvxBoxItemLine::RIGHT)); + + // Adding the merged border properties to new cell + pNewItem->GetItemSetWritable().Put(aNewBox); + + // Remove existing cell's border formatting + SfxItemSet aSet(*pSetToPut); + aSet.ClearItem(ATTR_BORDER); + + // Adding remaining properties + pNewItem->GetItemSetWritable().Put(aSet); + } + else + pNewItem->GetItemSetWritable().Put(*pSetToPut); + } + else + pNewItem->GetItemSetWritable().Put(*pSetToPut); } m_aCache.emplace_back(rOrigItem, CellAttributeHolder(pNewItem, true)); diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx index 295cd1f442c7..f102150090f5 100644 --- a/sc/source/core/data/table4.cxx +++ b/sc/source/core/data/table4.cxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include +#include #include #include #include @@ -56,6 +58,8 @@ #include #include +using namespace Autoformat; + #define D_MAX_LONG_ double(0x7fffffff) namespace { @@ -2673,7 +2677,7 @@ void ScTable::AutoFormatArea(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SC const ScPatternAttr& rAttr, sal_uInt16 nFormatNo) { ScAutoFormat& rFormat = *ScGlobal::GetOrCreateAutoFormat(); - ScAutoFormatData* pData = rFormat.findByIndex(nFormatNo); + ScAutoFormatData* pData = rFormat.GetData(nFormatNo); if (pData) { ApplyPatternArea(nStartCol, nStartRow, nEndCol, nEndRow, rAttr); @@ -2687,228 +2691,108 @@ void ScTable::AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW return; ScAutoFormat& rFormat = *ScGlobal::GetOrCreateAutoFormat(); - ScAutoFormatData* pData = rFormat.findByIndex(nFormatNo); + const ScAutoFormatData* pData = rFormat.GetResolvedStyle(rFormat.GetData(nFormatNo)); if (!pData) return; - std::unique_ptr pPatternAttrs[16]; - for (sal_uInt8 i = 0; i < 16; ++i) + std::unique_ptr pPatternAttrs[ELEMENT_COUNT]; + for (sal_uInt8 i = 0; i < ELEMENT_COUNT; ++i) { pPatternAttrs[i].reset(new ScPatternAttr(rDocument.getCellAttributeHelper())); - pData->FillToItemSet(i, pPatternAttrs[i]->GetItemSetWritable(), rDocument); + pData->FillToItemSet(i, pPatternAttrs[i]->GetItemSetWritable()); } - // Important special case: when the whole rows are selected. Then applying autoformat to right - // column individually would create all columns. In this case, assume that right column isn't - // needed, to allow "to the end of row" format optimization (which doesn't create columns). - // Keep left column in this case, because it may be pre-formatted for categories. To enable the - // optimization, apply uniform format row by row where possible, not column by column. + // Reset cell autoformat before applying new one + DeleteArea(nStartCol, nStartRow, nEndCol, nEndRow, InsertDeleteFlags::ATTRIB); - const bool isWholeRows = nStartCol == 0 && nEndCol == rDocument.MaxCol(); + AutoFormatArea(nStartCol, nStartRow, nEndCol, nEndRow, *pPatternAttrs[BACKGROUND], nFormatNo); + AutoFormatArea(nStartCol, nStartRow, nEndCol, nEndRow, *pPatternAttrs[BODY], nFormatNo); - //////////////////////////////////////////////////////////////////////////////////////////////// - // Top row data indexes: - // 0 - left corner style - // 1 - odd columns style - // 2 - even column style - // 3 - right corner style - //////////////////////////////////////////////////////////////////////////////////////////////// - - SCCOL startOffset = 1; - // Left top corner - if (pData->HasSameData(0, 1) && pData->HasSameData(0, 2)) - startOffset = 0; // Left corner is same as the rest of the row - else - AutoFormatArea(nStartCol, nStartRow, nStartCol, nStartRow, *pPatternAttrs[0], nFormatNo); - - SCCOL endOffset = 1; - // Right top corner: ignore when whole rows selected - if (isWholeRows || (pData->HasSameData(3, 1) && pData->HasSameData(3, 2))) - endOffset = 0; // Right corner is same as the rest of the row (most important case) - else - AutoFormatArea(nEndCol, nStartRow, nEndCol, nStartRow, *pPatternAttrs[3], nFormatNo); - - // Top row - if (pData->HasSameData(1, 2)) - AutoFormatArea(nStartCol + startOffset, nStartRow, nEndCol - endOffset, nStartRow, *pPatternAttrs[1], nFormatNo); - else - { - sal_uInt16 nIndex = 1; - for (SCCOL nCol = nStartCol + startOffset; nCol <= nEndCol - endOffset; nCol++) - { - AutoFormatArea(nCol, nStartRow, nCol, nStartRow, *pPatternAttrs[nIndex], nFormatNo); - if (nIndex == 1) - nIndex = 2; - else - nIndex = 1; - } - } - - //////////////////////////////////////////////////////////////////////////////////////////////// - // Body data indexes: - // 4 - left column odd row style - // 8 - left column even row style - // 7 - right column odd row style - // 11 - right column even row style - // 5 - body odd column odd row style - // 6 - body even column odd row style - // 9 - body odd column even row style - // 10 - body even column even row style - //////////////////////////////////////////////////////////////////////////////////////////////// - - startOffset = 1; - // Left column - if (pData->HasSameData(4, 5) && pData->HasSameData(4, 6) && pData->HasSameData(8, 9) && pData->HasSameData(8, 10)) - startOffset = 0; // Left column is same as the lines of the body - else - { - if (pData->HasSameData(4, 8)) // even and odd rows are same - AutoFormatArea(nStartCol, nStartRow + 1, nStartCol, nEndRow - 1, *pPatternAttrs[4], nFormatNo); - else - { - sal_uInt16 nIndex = 4; - for (SCROW nRow = nStartRow + 1; nRow < nEndRow; nRow++) - { - AutoFormatArea(nStartCol, nRow, nStartCol, nRow, *pPatternAttrs[nIndex], nFormatNo); - if (nIndex == 4) - nIndex = 8; - else - nIndex = 4; - } - } - } - - endOffset = 1; - // Right column: ignore when whole rows selected - if (isWholeRows || (pData->HasSameData(7, 5) && pData->HasSameData(7, 6) && pData->HasSameData(11, 9) && pData->HasSameData(11, 10))) - endOffset = 0; // Right column is same as the lines of the body (most important case) - else - { - if (pData->HasSameData(7, 11)) // even and odd rows are same - AutoFormatArea(nEndCol, nStartRow + 1, nEndCol, nEndRow - 1, *pPatternAttrs[7], nFormatNo); - else - { - sal_uInt16 nIndex = 7; - for (SCROW nRow = nStartRow + 1; nRow < nEndRow; nRow++) - { - AutoFormatArea(nEndCol, nRow, nEndCol, nRow, *pPatternAttrs[nIndex], nFormatNo); - if (nIndex == 7) - nIndex = 11; - else - nIndex = 7; - } - } - } - - // Body - if (pData->HasSameData(5, 6) && pData->HasSameData(9, 10)) // Odd and even columns are same (most important case) - { - if (pData->HasSameData(5, 9)) // Everything is the same - AutoFormatArea(nStartCol + startOffset, nStartRow + 1, nEndCol - endOffset, nEndRow - 1, *pPatternAttrs[5], nFormatNo); - else // Odd and even rows differ - { - if (pProgress) - pProgress->SetState(1, nEndRow - nStartRow + 3); // account for elements outside the "Body" block - sal_uInt16 nIndex = 5; - for (SCROW nRow = nStartRow + 1; nRow < nEndRow; nRow++) - { - AutoFormatArea(nStartCol + startOffset, nRow, nEndCol - endOffset, nRow, *pPatternAttrs[nIndex], nFormatNo); - if (nIndex == 5) - nIndex = 9; - else - nIndex = 5; - if (pProgress) - pProgress->SetStateOnPercent(nRow - nStartRow + 1); - } - } - } - else if (pData->HasSameData(5, 9) && pData->HasSameData(6, 10)) // odd and even rows are same + sal_uInt8 nIndex = ODD_COL; + if (pData->UseBandedColStyles()) { if (pProgress) - pProgress->SetState(1, nEndCol - nStartCol + 3); // account for elements outside the "Body" block - sal_uInt16 nIndex = 5; - for (SCCOL nCol = nStartCol + startOffset; nCol <= nEndCol - endOffset; nCol++) + pProgress->SetState(1, nEndCol - nStartCol); + + for (SCROW nCol = nStartCol; nCol <= nEndCol; nCol++) { - AutoFormatArea(nCol, nStartRow + 1, nCol, nEndRow - 1, *pPatternAttrs[nIndex], nFormatNo); - if (nIndex == 5) - nIndex = 6; - else - nIndex = 5; + AutoFormatArea(nCol, nStartRow, nCol, nEndRow, *pPatternAttrs[nIndex], nFormatNo); + nIndex = nIndex == ODD_COL ? EVEN_COL : ODD_COL; + if (pProgress) - pProgress->SetStateOnPercent(nCol - nStartCol + 1); + pProgress->SetStateOnPercent(nCol - nStartCol); } } - else // Everything is different + + if (pData->UseBandedRowStyles()) { + nIndex = ODD_ROW; if (pProgress) - pProgress->SetState(1, nEndCol - nStartCol + 3); // account for elements outside the "Body" block - sal_uInt16 nIndex = 5; - for (SCCOL nCol = nStartCol + startOffset; nCol <= nEndCol - endOffset; nCol++) + pProgress->SetState(1, nEndRow - nStartRow); + for (SCROW nRow = nStartRow; nRow <= nEndRow; nRow++) { - for (SCROW nRow = nStartRow + 1; nRow < nEndRow; nRow++) - { - AutoFormatArea(nCol, nRow, nCol, nRow, *pPatternAttrs[nIndex], nFormatNo); - if ((nIndex == 5) || (nIndex == 9)) - { - if (nIndex == 5) - nIndex = 9; - else - nIndex = 5; - } - else - { - if (nIndex == 6) - nIndex = 10; - else - nIndex = 6; - } - } // for nRow - if ((nIndex == 5) || (nIndex == 9)) - nIndex = 6; - else - nIndex = 5; + AutoFormatArea(nStartCol, nRow, nEndCol, nRow, *pPatternAttrs[nIndex], nFormatNo); + nIndex = nIndex == ODD_ROW ? EVEN_ROW : ODD_ROW; + if (pProgress) - pProgress->SetStateOnPercent(nCol - nStartCol + 1); + pProgress->SetStateOnPercent(nRow - nStartCol); + } + } - } // for nCol - } // if not all equal - - //////////////////////////////////////////////////////////////////////////////////////////////// - // Bottom row data indexes: - // 12 - left corner style - // 13 - odd columns style - // 14 - even column style - // 15 - right corner style - //////////////////////////////////////////////////////////////////////////////////////////////// - - startOffset = 1; - // Left bottom corner - if (pData->HasSameData(12, 13) && pData->HasSameData(12, 14)) - startOffset = 0; - else - AutoFormatArea(nStartCol, nEndRow, nStartCol, nEndRow, *pPatternAttrs[12], nFormatNo); - - endOffset = 1; - // Right bottom corner: ignore when whole rows selected - if (isWholeRows || (pData->HasSameData(15, 13) && pData->HasSameData(15, 14))) - endOffset = 0; - else - AutoFormatArea(nEndCol, nEndRow, nEndCol, nEndRow, *pPatternAttrs[15], nFormatNo); - - // Bottom row - if (pData->HasSameData(13, 14)) - AutoFormatArea(nStartCol + startOffset, nEndRow, nEndCol - endOffset, nEndRow, *pPatternAttrs[13], nFormatNo); - else + if (pData->UseLastColStyles()) { - sal_uInt16 nIndex = 13; - for (SCCOL nCol = nStartCol + startOffset; nCol <= nEndCol - endOffset; nCol++) + nIndex = LAST_COL; + for (SCROW nRow = nStartRow; nRow <= nEndRow; nRow++) + { + AutoFormatArea(nEndCol, nRow, nEndCol, nRow, *pPatternAttrs[nIndex], nFormatNo); + } + } + + if (pData->UseFirstColStyles()) + { + nIndex = FIRST_COL; + for (SCROW nRow = nStartRow; nRow <= nEndRow; nRow++) + { + AutoFormatArea(nStartCol, nRow, nStartCol, nRow, *pPatternAttrs[nIndex], nFormatNo); + } + } + + if (pData->UseLastRowStyles()) + { + nIndex = LAST_ROW; + for (SCROW nCol = nStartCol; nCol <= nEndCol; nCol++) { AutoFormatArea(nCol, nEndRow, nCol, nEndRow, *pPatternAttrs[nIndex], nFormatNo); - if (nIndex == 13) - nIndex = 14; - else - nIndex = 13; } + nIndex = LAST_ROW_EVEN_COL; + for (SCROW nCol = nStartCol + 1; nCol <= nEndCol; nCol += 2) + { + AutoFormatArea(nCol, nEndRow, nCol, nEndRow, *pPatternAttrs[nIndex], nFormatNo); + } + nIndex = LAST_ROW_END_COL; + AutoFormatArea(nEndCol, nEndRow, nEndCol, nEndRow, *pPatternAttrs[nIndex], nFormatNo); + nIndex = LAST_ROW_START_COL; + AutoFormatArea(nStartCol, nEndRow, nStartCol, nEndRow, *pPatternAttrs[nIndex], nFormatNo); + } + + if (pData->UseFirstRowStyles()) + { + nIndex = FIRST_ROW; + for (SCROW nCol = nStartCol; nCol <= nEndCol; nCol++) + { + AutoFormatArea(nCol, nStartRow, nCol, nStartRow, *pPatternAttrs[nIndex], nFormatNo); + } + + nIndex = FIRST_ROW_EVEN_COL; + for (SCROW nCol = nStartCol + 1; nCol <= nEndCol; nCol += 2) + { + AutoFormatArea(nCol, nStartRow, nCol, nStartRow, *pPatternAttrs[nIndex], nFormatNo); + } + nIndex = FIRST_ROW_END_COL; + AutoFormatArea(nEndCol, nStartRow, nEndCol, nStartRow, *pPatternAttrs[nIndex], nFormatNo); + nIndex = FIRST_ROW_START_COL; + AutoFormatArea(nStartCol, nStartRow, nStartCol, nStartRow, *pPatternAttrs[nIndex], + nFormatNo); } } @@ -2916,7 +2800,7 @@ void ScTable::GetAutoFormatAttr(SCCOL nCol, SCROW nRow, sal_uInt16 nIndex, ScAut { sal_uInt32 nFormatIndex = GetNumberFormat( nCol, nRow ); ScNumFormatAbbrev aNumFormat( nFormatIndex, *rDocument.GetFormatTable() ); - rData.GetFromItemSet( nIndex, GetPattern( nCol, nRow )->GetItemSet(), aNumFormat ); + rData.GetFromItemSet( nIndex, GetPattern( nCol, nRow )->GetItemSet()); } #define LF_LEFT 1 diff --git a/sc/source/core/tool/autoform.cxx b/sc/source/core/tool/autoform.cxx index c74deca0f72e..41ba083324db 100644 --- a/sc/source/core/tool/autoform.cxx +++ b/sc/source/core/tool/autoform.cxx @@ -17,16 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include #include +#include -#include -#include -#include #include #include -#include -#include #include #include #include @@ -47,112 +42,9 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * XXX: BIG RED NOTICE! Changes MUST be binary file format compatible and MUST - * be synchronized with Writer's SwTableAutoFmtTbl sw/source/core/doc/tblafmt.cxx - */ - -constexpr OUString sAutoTblFmtName = u"autotbl.fmt"_ustr; - -// till SO5PF -const sal_uInt16 AUTOFORMAT_ID_X = 9501; -const sal_uInt16 AUTOFORMAT_ID_358 = 9601; -const sal_uInt16 AUTOFORMAT_DATA_ID_X = 9502; - -// from SO5 on -// in following versions the value of the IDs must be higher -const sal_uInt16 AUTOFORMAT_ID_504 = 9801; -const sal_uInt16 AUTOFORMAT_DATA_ID_504 = 9802; - -const sal_uInt16 AUTOFORMAT_DATA_ID_552 = 9902; - -// --- from 680/dr25 on: store strings as UTF-8 -const sal_uInt16 AUTOFORMAT_ID_680DR25 = 10021; - -// --- Bug fix to fdo#31005: Table Autoformats does not save/apply all properties (Writer and Calc) -const sal_uInt16 AUTOFORMAT_ID_31005 = 10041; -const sal_uInt16 AUTOFORMAT_DATA_ID_31005 = 10042; - -// current version -const sal_uInt16 AUTOFORMAT_ID = AUTOFORMAT_ID_31005; -const sal_uInt16 AUTOFORMAT_DATA_ID = AUTOFORMAT_DATA_ID_31005; - -namespace -{ - /// Read an AutoFormatSwBlob from stream. - SvStream& operator>>(SvStream &stream, AutoFormatSwBlob &blob) - { - blob.Reset(); - - sal_uInt64 endOfBlob = 0; - stream.ReadUInt64( endOfBlob ); - - const sal_uInt64 currentPosition = stream.Tell(); - const sal_uInt64 blobSize = endOfBlob - currentPosition; - // A zero-size indicates an empty blob. This happens when Calc creates a new autoformat, - // since it (naturally) doesn't have any writer-specific data to write. - if (blobSize) - { - blob.pData.reset(new sal_uInt8[blobSize]); - blob.size = static_cast(blobSize); - stream.ReadBytes(blob.pData.get(), blob.size); - } - - return stream; - } - - /// Write an AutoFormatSwBlob to stream. - SvStream& WriteAutoFormatSwBlob(SvStream &stream, const AutoFormatSwBlob &blob) - { - const sal_uInt64 endOfBlob = stream.Tell() + sizeof(sal_uInt64) + blob.size; - stream.WriteUInt64( endOfBlob ); - if (blob.size) - stream.WriteBytes(blob.pData.get(), blob.size); - - return stream; - } -} - -ScAfVersions::ScAfVersions() -{ -} - -void ScAfVersions::Load( SvStream& rStream, sal_uInt16 nVer ) -{ - LoadBlockA(rStream, nVer); - if (nVer >= AUTOFORMAT_ID_31005) - { - rStream >> swVersions; - } - LoadBlockB(rStream, nVer); -} - -void ScAfVersions::Write(SvStream& rStream, sal_uInt16 fileVersion) -{ - AutoFormatVersions::WriteBlockA(rStream, fileVersion); - - if (fileVersion >= SOFFICE_FILEFORMAT_50) - { - WriteAutoFormatSwBlob( rStream, swVersions ); - } - - AutoFormatVersions::WriteBlockB(rStream, fileVersion); -} +using namespace com::sun::star::beans; +using namespace com::sun::star; ScAutoFormatDataField::ScAutoFormatDataField() { @@ -171,8 +63,8 @@ ScAutoFormatDataField::ScAutoFormatDataField() m_aCTLHeight = std::make_unique(240, 100, ATTR_CTL_FONT_HEIGHT); m_aCTLWeight = std::make_unique(WEIGHT_NORMAL, ATTR_CTL_FONT_WEIGHT); m_aCTLPosture = std::make_unique(ITALIC_NONE, ATTR_CTL_FONT_POSTURE); - m_aUnderline = std::make_unique(LINESTYLE_NONE,ATTR_FONT_UNDERLINE); - m_aOverline = std::make_unique(LINESTYLE_NONE,ATTR_FONT_OVERLINE); + m_aUnderline = std::make_unique(LINESTYLE_NONE, ATTR_FONT_UNDERLINE); + m_aOverline = std::make_unique(LINESTYLE_NONE, ATTR_FONT_OVERLINE); m_aCrossedOut = std::make_unique(STRIKEOUT_NONE, ATTR_FONT_CROSSEDOUT); m_aContour = std::make_unique(false, ATTR_FONT_CONTOUR); m_aShadowed = std::make_unique(false, ATTR_FONT_SHADOWED); @@ -182,755 +74,389 @@ ScAutoFormatDataField::ScAutoFormatDataField() m_aBLTR = std::make_unique(ATTR_BORDER_BLTR); m_aBackground = std::make_unique(ATTR_BACKGROUND); m_aAdjust = std::make_unique(SvxAdjust::Left, 0); - m_aHorJustify = std::make_unique(SvxCellHorJustify::Standard, ATTR_HOR_JUSTIFY); - m_aVerJustify = std::make_unique(SvxCellVerJustify::Standard, ATTR_VER_JUSTIFY); - m_aStacked = std::make_unique(); + m_aHorJustify + = std::make_unique(SvxCellHorJustify::Standard, ATTR_HOR_JUSTIFY); + m_aVerJustify + = std::make_unique(SvxCellVerJustify::Standard, ATTR_VER_JUSTIFY); + m_aStacked = std::make_unique(ATTR_STACKED); m_aMargin = std::make_unique(ATTR_MARGIN); - m_aLinebreak = std::make_unique(); + m_aLinebreak = std::make_unique(ATTR_LINEBREAK); m_aRotateAngle = std::make_unique(0_deg100); m_aRotateMode = std::make_unique(SVX_ROTATE_MODE_STANDARD, ATTR_ROTATE_MODE); } -ScAutoFormatDataField::ScAutoFormatDataField( const ScAutoFormatDataField& rCopy ) -: AutoFormatBase(rCopy), - // m_swFields was not copied in original, needed? - aNumFormat( rCopy.aNumFormat ) +ScAutoFormatDataField::ScAutoFormatDataField(const ScAutoFormatDataField& rCopy) + : SvxAutoFormatDataField(rCopy) { } -ScAutoFormatDataField::~ScAutoFormatDataField() +ScAutoFormatDataField::ScAutoFormatDataField(const SvxAutoFormatDataField& rCopy) + : SvxAutoFormatDataField(rCopy) { } -bool ScAutoFormatDataField::Load( SvStream& rStream, const ScAfVersions& rVersions, sal_uInt16 nVer ) -{ - LoadBlockA( rStream, rVersions, nVer ); - - if (nVer >= AUTOFORMAT_DATA_ID_31005) - { - rStream >> m_swFields; - } - - LoadBlockB( rStream, rVersions, nVer ); - - if( 0 == rVersions.nNumFormatVersion ) - { - // --- from 680/dr25 on: store strings as UTF-8 - rtl_TextEncoding eCharSet = (nVer >= AUTOFORMAT_ID_680DR25) ? RTL_TEXTENCODING_UTF8 : rStream.GetStreamCharSet(); - aNumFormat.Load( rStream, eCharSet ); - } - - // adjust charset in font - rtl_TextEncoding eSysSet = osl_getThreadTextEncoding(); - rtl_TextEncoding eSrcSet = rStream.GetStreamCharSet(); - if( eSrcSet != eSysSet && m_aFont->GetCharSet() == eSrcSet ) - m_aFont->SetCharSet(eSysSet); - - return (rStream.GetError() == ERRCODE_NONE); -} - -bool ScAutoFormatDataField::Save( SvStream& rStream, sal_uInt16 fileVersion ) -{ - SaveBlockA( rStream, fileVersion ); - - if (fileVersion >= SOFFICE_FILEFORMAT_50) - { - WriteAutoFormatSwBlob( rStream, m_swFields ); - } - - SaveBlockB( rStream, fileVersion ); - - // --- from 680/dr25 on: store strings as UTF-8 - aNumFormat.Save( rStream, RTL_TEXTENCODING_UTF8 ); - - return (rStream.GetError() == ERRCODE_NONE); -} +ScAutoFormatDataField::~ScAutoFormatDataField() {} ScAutoFormatData::ScAutoFormatData() { - nStrResId = USHRT_MAX; - - bIncludeValueFormat = - bIncludeFont = - bIncludeJustify = - bIncludeFrame = - bIncludeBackground = - bIncludeWidthHeight = true; - - for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex ) - ppDataField[ nIndex ].reset( new ScAutoFormatDataField ); + for (size_t n = 0; n < ELEMENT_COUNT; n++) + mpDataField[n] = std::make_unique(); } -ScAutoFormatData::ScAutoFormatData( const ScAutoFormatData& rData ) : - aName( rData.aName ), - nStrResId( rData.nStrResId ), - bIncludeFont( rData.bIncludeFont ), - bIncludeJustify( rData.bIncludeJustify ), - bIncludeFrame( rData.bIncludeFrame ), - bIncludeBackground( rData.bIncludeBackground ), - bIncludeValueFormat( rData.bIncludeValueFormat ), - bIncludeWidthHeight( rData.bIncludeWidthHeight ) +ScAutoFormatData::ScAutoFormatData(const ScAutoFormatData& rData) + : SvxAutoFormatData(rData) { - for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex ) - ppDataField[ nIndex ].reset( new ScAutoFormatDataField( rData.GetField( nIndex ) ) ); + for (size_t n = 0; n < ELEMENT_COUNT; n++) + mpDataField[n].reset(new ScAutoFormatDataField(*rData.GetField(n))); } -ScAutoFormatData::~ScAutoFormatData() +ScAutoFormatData::ScAutoFormatData(const SvxAutoFormatData& rData) + : SvxAutoFormatData(rData) { + for (size_t n = 0; n < ELEMENT_COUNT; n++) + mpDataField[n].reset(new ScAutoFormatDataField(*rData.GetField(n))); } -ScAutoFormatDataField& ScAutoFormatData::GetField( sal_uInt16 nIndex ) +ScAutoFormatDataField* ScAutoFormatData::GetField(size_t nIndex) { - OSL_ENSURE( nIndex < 16, "ScAutoFormatData::GetField - illegal index" ); - OSL_ENSURE( ppDataField[ nIndex ], "ScAutoFormatData::GetField - no data" ); - return *ppDataField[ nIndex ]; + if (nIndex < ELEMENT_COUNT) + return mpDataField[nIndex].get(); + + SAL_WARN("sc", "ScAutoFormatData::GetField - index out of bounds: " << nIndex); + return nullptr; } -const ScAutoFormatDataField& ScAutoFormatData::GetField( sal_uInt16 nIndex ) const +const ScAutoFormatDataField* ScAutoFormatData::GetField(size_t nIndex) const { - OSL_ENSURE( nIndex < 16, "ScAutoFormatData::GetField - illegal index" ); - OSL_ENSURE( ppDataField[ nIndex ], "ScAutoFormatData::GetField - no data" ); - return *ppDataField[ nIndex ]; + if (nIndex < ELEMENT_COUNT) + return mpDataField[nIndex].get(); + + SAL_WARN("sc", "ScAutoFormatData::GetField - index out of bounds: " << nIndex); + return nullptr; } -const SfxPoolItem* ScAutoFormatData::GetItem( sal_uInt16 nIndex, sal_uInt16 nWhich ) const +bool ScAutoFormatData::SetField(size_t nIndex, const SvxAutoFormatDataField& aField) { - const ScAutoFormatDataField& rField = GetField( nIndex ); - switch( nWhich ) + if (nIndex < ELEMENT_COUNT) { - case ATTR_FONT: return &rField.GetFont(); - case ATTR_FONT_HEIGHT: return &rField.GetHeight(); - case ATTR_FONT_WEIGHT: return &rField.GetWeight(); - case ATTR_FONT_POSTURE: return &rField.GetPosture(); - case ATTR_CJK_FONT: return &rField.GetCJKFont(); - case ATTR_CJK_FONT_HEIGHT: return &rField.GetCJKHeight(); - case ATTR_CJK_FONT_WEIGHT: return &rField.GetCJKWeight(); - case ATTR_CJK_FONT_POSTURE: return &rField.GetCJKPosture(); - case ATTR_CTL_FONT: return &rField.GetCTLFont(); - case ATTR_CTL_FONT_HEIGHT: return &rField.GetCTLHeight(); - case ATTR_CTL_FONT_WEIGHT: return &rField.GetCTLWeight(); - case ATTR_CTL_FONT_POSTURE: return &rField.GetCTLPosture(); - case ATTR_FONT_UNDERLINE: return &rField.GetUnderline(); - case ATTR_FONT_OVERLINE: return &rField.GetOverline(); - case ATTR_FONT_CROSSEDOUT: return &rField.GetCrossedOut(); - case ATTR_FONT_CONTOUR: return &rField.GetContour(); - case ATTR_FONT_SHADOWED: return &rField.GetShadowed(); - case ATTR_FONT_COLOR: return &rField.GetColor(); - case ATTR_BORDER: return &rField.GetBox(); - case ATTR_BORDER_TLBR: return &rField.GetTLBR(); - case ATTR_BORDER_BLTR: return &rField.GetBLTR(); - case ATTR_BACKGROUND: return &rField.GetBackground(); - case ATTR_HOR_JUSTIFY: return &rField.GetHorJustify(); - case ATTR_VER_JUSTIFY: return &rField.GetVerJustify(); - case ATTR_STACKED: return &rField.GetStacked(); - case ATTR_MARGIN: return &rField.GetMargin(); - case ATTR_LINEBREAK: return &rField.GetLinebreak(); - case ATTR_ROTATE_VALUE: return &rField.GetRotateAngle(); - case ATTR_ROTATE_MODE: return &rField.GetRotateMode(); + mpDataField[nIndex] = std::make_unique(aField); + return true; + } + + SAL_WARN("sc", "ScAutoFormatData::SetField - index out of bounds: " << nIndex); + return false; +} + +const SfxPoolItem* ScAutoFormatData::GetItem(sal_uInt8 nIndex, sal_uInt16 nWhich) const +{ + const ScAutoFormatDataField& rField = *GetField(nIndex); + switch (nWhich) + { + case ATTR_FONT: + return &rField.GetFont(); + case ATTR_FONT_HEIGHT: + return &rField.GetHeight(); + case ATTR_FONT_WEIGHT: + return &rField.GetWeight(); + case ATTR_FONT_POSTURE: + return &rField.GetPosture(); + case ATTR_CJK_FONT: + return &rField.GetCJKFont(); + case ATTR_CJK_FONT_HEIGHT: + return &rField.GetCJKHeight(); + case ATTR_CJK_FONT_WEIGHT: + return &rField.GetCJKWeight(); + case ATTR_CJK_FONT_POSTURE: + return &rField.GetCJKPosture(); + case ATTR_CTL_FONT: + return &rField.GetCTLFont(); + case ATTR_CTL_FONT_HEIGHT: + return &rField.GetCTLHeight(); + case ATTR_CTL_FONT_WEIGHT: + return &rField.GetCTLWeight(); + case ATTR_CTL_FONT_POSTURE: + return &rField.GetCTLPosture(); + case ATTR_FONT_UNDERLINE: + return &rField.GetUnderline(); + case ATTR_FONT_OVERLINE: + return &rField.GetOverline(); + case ATTR_FONT_CROSSEDOUT: + return &rField.GetCrossedOut(); + case ATTR_FONT_CONTOUR: + return &rField.GetContour(); + case ATTR_FONT_SHADOWED: + return &rField.GetShadowed(); + case ATTR_FONT_COLOR: + return &rField.GetColor(); + case ATTR_BORDER: + return &rField.GetBox(); + case ATTR_BORDER_TLBR: + return &rField.GetTLBR(); + case ATTR_BORDER_BLTR: + return &rField.GetBLTR(); + case ATTR_BACKGROUND: + return &rField.GetBackground(); + case ATTR_HOR_JUSTIFY: + return &rField.GetHorJustify(); + case ATTR_VER_JUSTIFY: + return &rField.GetVerJustify(); + case ATTR_STACKED: + return &rField.GetStacked(); + case ATTR_MARGIN: + return &rField.GetMargin(); + case ATTR_LINEBREAK: + return &rField.GetLinebreak(); + case ATTR_ROTATE_VALUE: + return &rField.GetRotateAngle(); + case ATTR_ROTATE_MODE: + return &rField.GetRotateMode(); } return nullptr; } -void ScAutoFormatData::PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem ) +void ScAutoFormatData::PutItem(size_t nIndex, const SfxPoolItem& rItem) { - ScAutoFormatDataField& rField = GetField( nIndex ); - switch( rItem.Which() ) + ScAutoFormatDataField* rField = GetField(nIndex); + switch (rItem.Which()) { - case ATTR_FONT: rField.SetFont( rItem.StaticWhichCast(ATTR_FONT) ); break; - case ATTR_FONT_HEIGHT: rField.SetHeight( rItem.StaticWhichCast(ATTR_FONT_HEIGHT) ); break; - case ATTR_FONT_WEIGHT: rField.SetWeight( rItem.StaticWhichCast(ATTR_FONT_WEIGHT) ); break; - case ATTR_FONT_POSTURE: rField.SetPosture( rItem.StaticWhichCast(ATTR_FONT_POSTURE) ); break; - case ATTR_CJK_FONT: rField.SetCJKFont( rItem.StaticWhichCast(ATTR_CJK_FONT) ); break; - case ATTR_CJK_FONT_HEIGHT: rField.SetCJKHeight( rItem.StaticWhichCast(ATTR_CJK_FONT_HEIGHT) ); break; - case ATTR_CJK_FONT_WEIGHT: rField.SetCJKWeight( rItem.StaticWhichCast(ATTR_CJK_FONT_WEIGHT) ); break; - case ATTR_CJK_FONT_POSTURE: rField.SetCJKPosture( rItem.StaticWhichCast(ATTR_CJK_FONT_POSTURE) ); break; - case ATTR_CTL_FONT: rField.SetCTLFont( rItem.StaticWhichCast(ATTR_CTL_FONT) ); break; - case ATTR_CTL_FONT_HEIGHT: rField.SetCTLHeight( rItem.StaticWhichCast(ATTR_CTL_FONT_HEIGHT) ); break; - case ATTR_CTL_FONT_WEIGHT: rField.SetCTLWeight( rItem.StaticWhichCast(ATTR_CTL_FONT_WEIGHT) ); break; - case ATTR_CTL_FONT_POSTURE: rField.SetCTLPosture( rItem.StaticWhichCast(ATTR_CTL_FONT_POSTURE) ); break; - case ATTR_FONT_UNDERLINE: rField.SetUnderline( rItem.StaticWhichCast(ATTR_FONT_UNDERLINE) ); break; - case ATTR_FONT_OVERLINE: rField.SetOverline( rItem.StaticWhichCast(ATTR_FONT_OVERLINE) ); break; - case ATTR_FONT_CROSSEDOUT: rField.SetCrossedOut( rItem.StaticWhichCast(ATTR_FONT_CROSSEDOUT) ); break; - case ATTR_FONT_CONTOUR: rField.SetContour( rItem.StaticWhichCast(ATTR_FONT_CONTOUR) ); break; - case ATTR_FONT_SHADOWED: rField.SetShadowed( rItem.StaticWhichCast(ATTR_FONT_SHADOWED) ); break; - case ATTR_FONT_COLOR: rField.SetColor( rItem.StaticWhichCast(ATTR_FONT_COLOR) ); break; - case ATTR_BORDER: rField.SetBox( rItem.StaticWhichCast(ATTR_BORDER) ); break; - case ATTR_BORDER_TLBR: rField.SetTLBR( rItem.StaticWhichCast(ATTR_BORDER_TLBR) ); break; - case ATTR_BORDER_BLTR: rField.SetBLTR( rItem.StaticWhichCast(ATTR_BORDER_BLTR) ); break; - case ATTR_BACKGROUND: rField.SetBackground( rItem.StaticWhichCast(ATTR_BACKGROUND) ); break; - case ATTR_HOR_JUSTIFY: rField.SetHorJustify( rItem.StaticWhichCast(ATTR_HOR_JUSTIFY) ); break; - case ATTR_VER_JUSTIFY: rField.SetVerJustify( rItem.StaticWhichCast(ATTR_VER_JUSTIFY) ); break; - case ATTR_STACKED: rField.SetStacked( rItem.StaticWhichCast(ATTR_STACKED) ); break; - case ATTR_MARGIN: rField.SetMargin( rItem.StaticWhichCast(ATTR_MARGIN) ); break; - case ATTR_LINEBREAK: rField.SetLinebreak( rItem.StaticWhichCast(ATTR_LINEBREAK) ); break; - case ATTR_ROTATE_VALUE: rField.SetRotateAngle( rItem.StaticWhichCast(ATTR_ROTATE_VALUE) ); break; - case ATTR_ROTATE_MODE: rField.SetRotateMode( rItem.StaticWhichCast(ATTR_ROTATE_MODE) ); break; + case ATTR_FONT: + rField->SetFont(rItem.StaticWhichCast(ATTR_FONT)); + break; + case ATTR_FONT_HEIGHT: + rField->SetHeight(rItem.StaticWhichCast(ATTR_FONT_HEIGHT)); + break; + case ATTR_FONT_WEIGHT: + rField->SetWeight(rItem.StaticWhichCast(ATTR_FONT_WEIGHT)); + break; + case ATTR_FONT_POSTURE: + rField->SetPosture(rItem.StaticWhichCast(ATTR_FONT_POSTURE)); + break; + case ATTR_CJK_FONT: + rField->SetCJKFont(rItem.StaticWhichCast(ATTR_CJK_FONT)); + break; + case ATTR_CJK_FONT_HEIGHT: + rField->SetCJKHeight(rItem.StaticWhichCast(ATTR_CJK_FONT_HEIGHT)); + break; + case ATTR_CJK_FONT_WEIGHT: + rField->SetCJKWeight(rItem.StaticWhichCast(ATTR_CJK_FONT_WEIGHT)); + break; + case ATTR_CJK_FONT_POSTURE: + rField->SetCJKPosture(rItem.StaticWhichCast(ATTR_CJK_FONT_POSTURE)); + break; + case ATTR_CTL_FONT: + rField->SetCTLFont(rItem.StaticWhichCast(ATTR_CTL_FONT)); + break; + case ATTR_CTL_FONT_HEIGHT: + rField->SetCTLHeight(rItem.StaticWhichCast(ATTR_CTL_FONT_HEIGHT)); + break; + case ATTR_CTL_FONT_WEIGHT: + rField->SetCTLWeight(rItem.StaticWhichCast(ATTR_CTL_FONT_WEIGHT)); + break; + case ATTR_CTL_FONT_POSTURE: + rField->SetCTLPosture(rItem.StaticWhichCast(ATTR_CTL_FONT_POSTURE)); + break; + case ATTR_FONT_UNDERLINE: + rField->SetUnderline(rItem.StaticWhichCast(ATTR_FONT_UNDERLINE)); + break; + case ATTR_FONT_OVERLINE: + rField->SetOverline(rItem.StaticWhichCast(ATTR_FONT_OVERLINE)); + break; + case ATTR_FONT_CROSSEDOUT: + rField->SetCrossedOut(rItem.StaticWhichCast(ATTR_FONT_CROSSEDOUT)); + break; + case ATTR_FONT_CONTOUR: + rField->SetContour(rItem.StaticWhichCast(ATTR_FONT_CONTOUR)); + break; + case ATTR_FONT_SHADOWED: + rField->SetShadowed(rItem.StaticWhichCast(ATTR_FONT_SHADOWED)); + break; + case ATTR_FONT_COLOR: + rField->SetColor(rItem.StaticWhichCast(ATTR_FONT_COLOR)); + break; + case ATTR_BORDER: + rField->SetBox(rItem.StaticWhichCast(ATTR_BORDER)); + break; + case ATTR_BORDER_TLBR: + rField->SetTLBR(rItem.StaticWhichCast(ATTR_BORDER_TLBR)); + break; + case ATTR_BORDER_BLTR: + rField->SetBLTR(rItem.StaticWhichCast(ATTR_BORDER_BLTR)); + break; + case ATTR_BACKGROUND: + rField->SetBackground(rItem.StaticWhichCast(ATTR_BACKGROUND)); + break; + case ATTR_HOR_JUSTIFY: + rField->SetHorJustify(rItem.StaticWhichCast(ATTR_HOR_JUSTIFY)); + break; + case ATTR_VER_JUSTIFY: + rField->SetVerJustify(rItem.StaticWhichCast(ATTR_VER_JUSTIFY)); + break; + case ATTR_STACKED: + rField->SetStacked(rItem.StaticWhichCast(ATTR_STACKED)); + break; + case ATTR_MARGIN: + rField->SetMargin(rItem.StaticWhichCast(ATTR_MARGIN)); + break; + case ATTR_LINEBREAK: + rField->SetLinebreak(rItem.StaticWhichCast(ATTR_LINEBREAK)); + break; + case ATTR_ROTATE_VALUE: + rField->SetRotateAngle(rItem.StaticWhichCast(ATTR_ROTATE_VALUE)); + break; + case ATTR_ROTATE_MODE: + rField->SetRotateMode(rItem.StaticWhichCast(ATTR_ROTATE_MODE)); + break; } } -void ScAutoFormatData::CopyItem( sal_uInt16 nToIndex, sal_uInt16 nFromIndex, sal_uInt16 nWhich ) +void ScAutoFormatData::CopyItem( size_t nToIndex, size_t nFromIndex, sal_uInt16 nWhich ) { const SfxPoolItem* pItem = GetItem( nFromIndex, nWhich ); if( pItem ) PutItem( nToIndex, *pItem ); } -const ScNumFormatAbbrev& ScAutoFormatData::GetNumFormat( sal_uInt16 nIndex ) const +void ScAutoFormatData::FillToItemSet(size_t nIndex, SfxItemSet& rItemSet) const { - return GetField( nIndex ).GetNumFormat(); + SvxAutoFormatData::FillToItemSet(nIndex, rItemSet); + + ScAutoFormatDataField rField = *GetField(nIndex), rDefault; + if (IsFrame()) + { + if (rField.GetBox() != rDefault.GetBox()) + { + SvxBoxItem aNewBox(rField.GetBox()); + SvxBoxItem aOldBox(rItemSet.Get(ATTR_BORDER)); + + if (!aNewBox.GetTop()) + aNewBox.SetLine(aOldBox.GetTop(), SvxBoxItemLine::TOP); + if (!aNewBox.GetBottom()) + aNewBox.SetLine(aOldBox.GetBottom(), SvxBoxItemLine::BOTTOM); + if (!aNewBox.GetLeft()) + aNewBox.SetLine(aOldBox.GetLeft(), SvxBoxItemLine::LEFT); + if (!aNewBox.GetRight()) + aNewBox.SetLine(aOldBox.GetRight(), SvxBoxItemLine::RIGHT); + if (!aNewBox.GetDistance(SvxBoxItemLine::RIGHT)) + aNewBox.SetAllDistances(aOldBox.GetDistance(SvxBoxItemLine::RIGHT)); + + rItemSet.Put(aNewBox); + } + } } -bool ScAutoFormatData::HasSameData( sal_uInt16 nIndex1, sal_uInt16 nIndex2 ) const +void ScAutoFormatData::GetFromItemSet(size_t nIndex, const SfxItemSet& rItemSet) { - bool bEqual = true; - const ScAutoFormatDataField& rField1 = GetField( nIndex1 ); - const ScAutoFormatDataField& rField2 = GetField( nIndex2 ); + ScAutoFormatDataField& rField = *GetField(nIndex); - if( bIncludeValueFormat ) - { - bEqual = bEqual - && (rField1.GetNumFormat() == rField2.GetNumFormat()); - } - if( bIncludeFont ) - { - bEqual = bEqual - && (rField1.GetFont() == rField2.GetFont()) - && (rField1.GetHeight() == rField2.GetHeight()) - && (rField1.GetWeight() == rField2.GetWeight()) - && (rField1.GetPosture() == rField2.GetPosture()) - && (rField1.GetCJKFont() == rField2.GetCJKFont()) - && (rField1.GetCJKHeight() == rField2.GetCJKHeight()) - && (rField1.GetCJKWeight() == rField2.GetCJKWeight()) - && (rField1.GetCJKPosture() == rField2.GetCJKPosture()) - && (rField1.GetCTLFont() == rField2.GetCTLFont()) - && (rField1.GetCTLHeight() == rField2.GetCTLHeight()) - && (rField1.GetCTLWeight() == rField2.GetCTLWeight()) - && (rField1.GetCTLPosture() == rField2.GetCTLPosture()) - && (rField1.GetUnderline() == rField2.GetUnderline()) - && (rField1.GetOverline() == rField2.GetOverline()) - && (rField1.GetCrossedOut() == rField2.GetCrossedOut()) - && (rField1.GetContour() == rField2.GetContour()) - && (rField1.GetShadowed() == rField2.GetShadowed()) - && (rField1.GetColor() == rField2.GetColor()); - } - if( bIncludeJustify ) - { - bEqual = bEqual - && (rField1.GetHorJustify() == rField2.GetHorJustify()) - && (rField1.GetVerJustify() == rField2.GetVerJustify()) - && (rField1.GetStacked() == rField2.GetStacked()) - && (rField1.GetLinebreak() == rField2.GetLinebreak()) - && (rField1.GetMargin() == rField2.GetMargin()) - && (rField1.GetRotateAngle() == rField2.GetRotateAngle()) - && (rField1.GetRotateMode() == rField2.GetRotateMode()); - } - if( bIncludeFrame ) - { - bEqual = bEqual - && (rField1.GetBox() == rField2.GetBox()) - && (rField1.GetTLBR() == rField2.GetTLBR()) - && (rField1.GetBLTR() == rField2.GetBLTR()); - } - if( bIncludeBackground ) - { - bEqual = bEqual - && (rField1.GetBackground() == rField2.GetBackground()); - } - return bEqual; + rField.SetFont(rItemSet.Get(ATTR_FONT)); + rField.SetHeight(rItemSet.Get(ATTR_FONT_HEIGHT)); + rField.SetWeight(rItemSet.Get(ATTR_FONT_WEIGHT)); + rField.SetPosture(rItemSet.Get(ATTR_FONT_POSTURE)); + rField.SetCJKFont(rItemSet.Get(ATTR_CJK_FONT)); + rField.SetCJKHeight(rItemSet.Get(ATTR_CJK_FONT_HEIGHT)); + rField.SetCJKWeight(rItemSet.Get(ATTR_CJK_FONT_WEIGHT)); + rField.SetCJKPosture(rItemSet.Get(ATTR_CJK_FONT_POSTURE)); + rField.SetCTLFont(rItemSet.Get(ATTR_CTL_FONT)); + rField.SetCTLHeight(rItemSet.Get(ATTR_CTL_FONT_HEIGHT)); + rField.SetCTLWeight(rItemSet.Get(ATTR_CTL_FONT_WEIGHT)); + rField.SetCTLPosture(rItemSet.Get(ATTR_CTL_FONT_POSTURE)); + rField.SetUnderline(rItemSet.Get(ATTR_FONT_UNDERLINE)); + rField.SetOverline(rItemSet.Get(ATTR_FONT_OVERLINE)); + rField.SetCrossedOut(rItemSet.Get(ATTR_FONT_CROSSEDOUT)); + rField.SetContour(rItemSet.Get(ATTR_FONT_CONTOUR)); + rField.SetShadowed(rItemSet.Get(ATTR_FONT_SHADOWED)); + rField.SetColor(rItemSet.Get(ATTR_FONT_COLOR)); + rField.SetTLBR(rItemSet.Get(ATTR_BORDER_TLBR)); + rField.SetBLTR(rItemSet.Get(ATTR_BORDER_BLTR)); + rField.SetHorJustify(rItemSet.Get(ATTR_HOR_JUSTIFY)); + rField.SetVerJustify(rItemSet.Get(ATTR_VER_JUSTIFY)); + rField.SetStacked(rItemSet.Get(ATTR_STACKED)); + rField.SetLinebreak(rItemSet.Get(ATTR_LINEBREAK)); + rField.SetMargin(rItemSet.Get(ATTR_MARGIN)); + rField.SetBackground(rItemSet.Get(ATTR_BACKGROUND)); + rField.SetRotateAngle(rItemSet.Get(ATTR_ROTATE_VALUE)); + rField.SetRotateMode(rItemSet.Get(ATTR_ROTATE_MODE)); } -void ScAutoFormatData::FillToItemSet( sal_uInt16 nIndex, SfxItemSet& rItemSet, const ScDocument& rDoc ) const +struct ScAutoFormat::Impl { - const ScAutoFormatDataField& rField = GetField( nIndex ); - - if( bIncludeValueFormat ) - { - ScNumFormatAbbrev& rNumFormat = const_cast(rField.GetNumFormat()); - SfxUInt32Item aValueFormat( ATTR_VALUE_FORMAT, 0 ); - aValueFormat.SetValue( rNumFormat.GetFormatIndex( *rDoc.GetFormatTable() ) ); - rItemSet.Put( aValueFormat ); - rItemSet.Put( SvxLanguageItem( rNumFormat.GetLanguage(), ATTR_LANGUAGE_FORMAT ) ); - } - if( bIncludeFont ) - { - rItemSet.Put( rField.GetFont() ); - rItemSet.Put( rField.GetHeight() ); - rItemSet.Put( rField.GetWeight() ); - rItemSet.Put( rField.GetPosture() ); - // do not insert empty CJK font - const SvxFontItem& rCJKFont = rField.GetCJKFont(); - if (!rCJKFont.GetStyleName().isEmpty()) - { - rItemSet.Put( rCJKFont ); - rItemSet.Put( rField.GetCJKHeight() ); - rItemSet.Put( rField.GetCJKWeight() ); - rItemSet.Put( rField.GetCJKPosture() ); - } - else - { - SvxFontHeightItem aFontHeightItem(rField.GetHeight()); - aFontHeightItem.SetWhich(ATTR_CJK_FONT_HEIGHT); - rItemSet.Put( aFontHeightItem ); - SvxWeightItem aWeightItem(rField.GetWeight()); - aWeightItem.SetWhich(ATTR_CJK_FONT_WEIGHT); - rItemSet.Put( aWeightItem ); - SvxPostureItem aPostureItem(rField.GetPosture()); - aPostureItem.SetWhich(ATTR_CJK_FONT_POSTURE); - rItemSet.Put( aPostureItem ); - } - // do not insert empty CTL font - const SvxFontItem& rCTLFont = rField.GetCTLFont(); - if (!rCTLFont.GetStyleName().isEmpty()) - { - rItemSet.Put( rCTLFont ); - rItemSet.Put( rField.GetCTLHeight() ); - rItemSet.Put( rField.GetCTLWeight() ); - rItemSet.Put( rField.GetCTLPosture() ); - } - else - { - SvxFontHeightItem aFontHeightItem(rField.GetHeight()); - aFontHeightItem.SetWhich(ATTR_CTL_FONT_HEIGHT); - rItemSet.Put( aFontHeightItem ); - SvxWeightItem aWeightItem(rField.GetWeight()); - aWeightItem.SetWhich(ATTR_CTL_FONT_WEIGHT); - rItemSet.Put( aWeightItem ); - SvxPostureItem aPostureItem(rField.GetPosture()); - aPostureItem.SetWhich(ATTR_CTL_FONT_POSTURE); - rItemSet.Put( aPostureItem ); - } - rItemSet.Put( rField.GetUnderline() ); - rItemSet.Put( rField.GetOverline() ); - rItemSet.Put( rField.GetCrossedOut() ); - rItemSet.Put( rField.GetContour() ); - rItemSet.Put( rField.GetShadowed() ); - rItemSet.Put( rField.GetColor() ); - } - if( bIncludeJustify ) - { - rItemSet.Put( rField.GetHorJustify() ); - rItemSet.Put( rField.GetVerJustify() ); - rItemSet.Put( rField.GetStacked() ); - rItemSet.Put( rField.GetLinebreak() ); - rItemSet.Put( rField.GetMargin() ); - rItemSet.Put( rField.GetRotateAngle() ); - rItemSet.Put( rField.GetRotateMode() ); - } - if( bIncludeFrame ) - { - rItemSet.Put( rField.GetBox() ); - rItemSet.Put( rField.GetTLBR() ); - rItemSet.Put( rField.GetBLTR() ); - } - if( bIncludeBackground ) - rItemSet.Put( rField.GetBackground() ); -} - -void ScAutoFormatData::GetFromItemSet( sal_uInt16 nIndex, const SfxItemSet& rItemSet, const ScNumFormatAbbrev& rNumFormat ) -{ - ScAutoFormatDataField& rField = GetField( nIndex ); - - rField.SetNumFormat ( rNumFormat); - rField.SetFont ( rItemSet.Get( ATTR_FONT ) ); - rField.SetHeight ( rItemSet.Get( ATTR_FONT_HEIGHT ) ); - rField.SetWeight ( rItemSet.Get( ATTR_FONT_WEIGHT ) ); - rField.SetPosture ( rItemSet.Get( ATTR_FONT_POSTURE ) ); - rField.SetCJKFont ( rItemSet.Get( ATTR_CJK_FONT ) ); - rField.SetCJKHeight ( rItemSet.Get( ATTR_CJK_FONT_HEIGHT ) ); - rField.SetCJKWeight ( rItemSet.Get( ATTR_CJK_FONT_WEIGHT ) ); - rField.SetCJKPosture ( rItemSet.Get( ATTR_CJK_FONT_POSTURE ) ); - rField.SetCTLFont ( rItemSet.Get( ATTR_CTL_FONT ) ); - rField.SetCTLHeight ( rItemSet.Get( ATTR_CTL_FONT_HEIGHT ) ); - rField.SetCTLWeight ( rItemSet.Get( ATTR_CTL_FONT_WEIGHT ) ); - rField.SetCTLPosture ( rItemSet.Get( ATTR_CTL_FONT_POSTURE ) ); - rField.SetUnderline ( rItemSet.Get( ATTR_FONT_UNDERLINE ) ); - rField.SetOverline ( rItemSet.Get( ATTR_FONT_OVERLINE ) ); - rField.SetCrossedOut ( rItemSet.Get( ATTR_FONT_CROSSEDOUT ) ); - rField.SetContour ( rItemSet.Get( ATTR_FONT_CONTOUR ) ); - rField.SetShadowed ( rItemSet.Get( ATTR_FONT_SHADOWED ) ); - rField.SetColor ( rItemSet.Get( ATTR_FONT_COLOR ) ); - rField.SetTLBR ( rItemSet.Get( ATTR_BORDER_TLBR ) ); - rField.SetBLTR ( rItemSet.Get( ATTR_BORDER_BLTR ) ); - rField.SetHorJustify ( rItemSet.Get( ATTR_HOR_JUSTIFY ) ); - rField.SetVerJustify ( rItemSet.Get( ATTR_VER_JUSTIFY ) ); - rField.SetStacked ( rItemSet.Get( ATTR_STACKED ) ); - rField.SetLinebreak ( rItemSet.Get( ATTR_LINEBREAK ) ); - rField.SetMargin ( rItemSet.Get( ATTR_MARGIN ) ); - rField.SetBackground ( rItemSet.Get( ATTR_BACKGROUND ) ); - rField.SetRotateAngle ( rItemSet.Get( ATTR_ROTATE_VALUE ) ); - rField.SetRotateMode ( rItemSet.Get( ATTR_ROTATE_MODE ) ); -} - -const TranslateId RID_SVXSTR_TBLAFMT[] = -{ - RID_SVXSTR_TBLAFMT_3D, - RID_SVXSTR_TBLAFMT_BLACK1, - RID_SVXSTR_TBLAFMT_BLACK2, - RID_SVXSTR_TBLAFMT_BLUE, - RID_SVXSTR_TBLAFMT_BROWN, - RID_SVXSTR_TBLAFMT_CURRENCY, - RID_SVXSTR_TBLAFMT_CURRENCY_3D, - RID_SVXSTR_TBLAFMT_CURRENCY_GRAY, - RID_SVXSTR_TBLAFMT_CURRENCY_LAVENDER, - RID_SVXSTR_TBLAFMT_CURRENCY_TURQUOISE, - RID_SVXSTR_TBLAFMT_GRAY, - RID_SVXSTR_TBLAFMT_GREEN, - RID_SVXSTR_TBLAFMT_LAVENDER, - RID_SVXSTR_TBLAFMT_RED, - RID_SVXSTR_TBLAFMT_TURQUOISE, - RID_SVXSTR_TBLAFMT_YELLOW, - RID_SVXSTR_TBLAFMT_LO6_ACADEMIC, - RID_SVXSTR_TBLAFMT_LO6_BOX_LIST_BLUE, - RID_SVXSTR_TBLAFMT_LO6_BOX_LIST_GREEN, - RID_SVXSTR_TBLAFMT_LO6_BOX_LIST_RED, - RID_SVXSTR_TBLAFMT_LO6_BOX_LIST_YELLOW, - RID_SVXSTR_TBLAFMT_LO6_ELEGANT, - RID_SVXSTR_TBLAFMT_LO6_FINANCIAL, - RID_SVXSTR_TBLAFMT_LO6_SIMPLE_GRID_COLUMNS, - RID_SVXSTR_TBLAFMT_LO6_SIMPLE_GRID_ROWS, - RID_SVXSTR_TBLAFMT_LO6_SIMPLE_LIST_SHADED + std::vector> maAutoFormats; }; -bool ScAutoFormatData::Load( SvStream& rStream, const ScAfVersions& rVersions ) +ScAutoFormat::ScAutoFormat() + : mpImpl(new Impl) { - sal_uInt16 nVer = 0; - rStream.ReadUInt16( nVer ); - bool bRet = ERRCODE_NONE == rStream.GetError(); - if( bRet && (nVer == AUTOFORMAT_DATA_ID_X || - (AUTOFORMAT_DATA_ID_504 <= nVer && nVer <= AUTOFORMAT_DATA_ID)) ) + SvxAutoFormat::Load(false); +} + +ScAutoFormat::~ScAutoFormat() = default; + +const ScAutoFormatData* ScAutoFormat::GetData(size_t nIndex) const +{ + return &*mpImpl->maAutoFormats[nIndex]; +} + +ScAutoFormatData* ScAutoFormat::GetData(size_t nIndex) { return &*mpImpl->maAutoFormats[nIndex]; } + +bool ScAutoFormat::InsertAutoFormat(SvxAutoFormatData* pFormat) +{ + if (!pFormat) { - // --- from 680/dr25 on: store strings as UTF-8 - if (nVer >= AUTOFORMAT_ID_680DR25) - { - aName = read_uInt16_lenPrefixed_uInt8s_ToOUString(rStream, - RTL_TEXTENCODING_UTF8); - } - else - aName = rStream.ReadUniOrByteString( rStream.GetStreamCharSet() ); - - if( AUTOFORMAT_DATA_ID_552 <= nVer ) - { - rStream.ReadUInt16( nStrResId ); - if (nStrResId < SAL_N_ELEMENTS(RID_SVXSTR_TBLAFMT)) - aName = SvxResId(RID_SVXSTR_TBLAFMT[nStrResId]); - else - nStrResId = USHRT_MAX; - } - - bool b; - rStream.ReadCharAsBool( b ); bIncludeFont = b; - rStream.ReadCharAsBool( b ); bIncludeJustify = b; - rStream.ReadCharAsBool( b ); bIncludeFrame = b; - rStream.ReadCharAsBool( b ); bIncludeBackground = b; - rStream.ReadCharAsBool( b ); bIncludeValueFormat = b; - rStream.ReadCharAsBool( b ); bIncludeWidthHeight = b; - - if (nVer >= AUTOFORMAT_DATA_ID_31005) - rStream >> m_swFields; - - bRet = ERRCODE_NONE == rStream.GetError(); - for( sal_uInt16 i = 0; bRet && i < 16; ++i ) - bRet = GetField( i ).Load( rStream, rVersions, nVer ); + SAL_WARN("sc", "Attempting to insert null format into ScAutoFormat"); + return false; } - else - bRet = false; - return bRet; + auto pNew = std::make_unique(*pFormat); + mpImpl->maAutoFormats.emplace_back(std::move(pNew)); + return true; } -bool ScAutoFormatData::Save(SvStream& rStream, sal_uInt16 fileVersion) +ScAutoFormatData* ScAutoFormat::ReleaseAutoFormat(const OUString& rName) { - rStream.WriteUInt16( AUTOFORMAT_DATA_ID ); - // --- from 680/dr25 on: store strings as UTF-8 - write_uInt16_lenPrefixed_uInt8s_FromOUString(rStream, aName, RTL_TEXTENCODING_UTF8); + ScAutoFormatData* pFormat = FindAutoFormat(rName); - rStream.WriteUInt16( nStrResId ); - rStream.WriteBool( bIncludeFont ); - rStream.WriteBool( bIncludeJustify ); - rStream.WriteBool( bIncludeFrame ); - rStream.WriteBool( bIncludeBackground ); - rStream.WriteBool( bIncludeValueFormat ); - rStream.WriteBool( bIncludeWidthHeight ); - - if (fileVersion >= SOFFICE_FILEFORMAT_50) - WriteAutoFormatSwBlob( rStream, m_swFields ); - - bool bRet = ERRCODE_NONE == rStream.GetError(); - for (sal_uInt16 i = 0; bRet && (i < 16); i++) - bRet = GetField( i ).Save( rStream, fileVersion ); - - return bRet; -} - -ScAutoFormat::ScAutoFormat() : - mbSaveLater(false) -{ - // create default autoformat - std::unique_ptr pData(new ScAutoFormatData); - OUString aName(ScResId(STR_STYLENAME_STANDARD)); - pData->SetName(aName); - - // default font, default height - vcl::Font aStdFont = OutputDevice::GetDefaultFont( - DefaultFontType::LATIN_SPREADSHEET, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::OnlyOne ); - SvxFontItem aFontItem( - aStdFont.GetFamilyTypeMaybeAskConfig(), aStdFont.GetFamilyName(), aStdFont.GetStyleName(), - aStdFont.GetPitchMaybeAskConfig(), aStdFont.GetCharSet(), ATTR_FONT ); - - aStdFont = OutputDevice::GetDefaultFont( - DefaultFontType::CJK_SPREADSHEET, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::OnlyOne ); - SvxFontItem aCJKFontItem( - aStdFont.GetFamilyTypeMaybeAskConfig(), aStdFont.GetFamilyName(), aStdFont.GetStyleName(), - aStdFont.GetPitchMaybeAskConfig(), aStdFont.GetCharSet(), ATTR_CJK_FONT ); - - aStdFont = OutputDevice::GetDefaultFont( - DefaultFontType::CTL_SPREADSHEET, LANGUAGE_ENGLISH_US, GetDefaultFontFlags::OnlyOne ); - SvxFontItem aCTLFontItem( - aStdFont.GetFamilyTypeMaybeAskConfig(), aStdFont.GetFamilyName(), aStdFont.GetStyleName(), - aStdFont.GetPitchMaybeAskConfig(), aStdFont.GetCharSet(), ATTR_CTL_FONT ); - - SvxFontHeightItem aHeight( 200, 100, ATTR_FONT_HEIGHT ); // 10 pt; - - // black thin border - Color aBlack( COL_BLACK ); - ::editeng::SvxBorderLine aLine( &aBlack, SvxBorderLineWidth::VeryThin ); - SvxBoxItem aBox( ATTR_BORDER ); - aBox.SetLine(&aLine, SvxBoxItemLine::LEFT); - aBox.SetLine(&aLine, SvxBoxItemLine::TOP); - aBox.SetLine(&aLine, SvxBoxItemLine::RIGHT); - aBox.SetLine(&aLine, SvxBoxItemLine::BOTTOM); - - Color aWhite(COL_WHITE); - SvxColorItem aWhiteText( aWhite, ATTR_FONT_COLOR ); - SvxColorItem aBlackText( aBlack, ATTR_FONT_COLOR ); - SvxBrushItem aBlueBack( COL_BLUE, ATTR_BACKGROUND ); - SvxBrushItem aWhiteBack( aWhite, ATTR_BACKGROUND ); - SvxBrushItem aGray70Back( Color(0x4d, 0x4d, 0x4d), ATTR_BACKGROUND ); - SvxBrushItem aGray20Back( Color(0xcc, 0xcc, 0xcc), ATTR_BACKGROUND ); - - for (sal_uInt16 i=0; i<16; i++) + std::unique_ptr pRet; + auto iter = std::find_if(mpImpl->maAutoFormats.begin(), mpImpl->maAutoFormats.end(), + [&pFormat](const std::unique_ptr& rpFormat) + { return rpFormat->GetName() == pFormat->GetName(); }); + if (iter != mpImpl->maAutoFormats.end()) { - pData->PutItem( i, aBox ); - pData->PutItem( i, aFontItem ); - pData->PutItem( i, aCJKFontItem ); - pData->PutItem( i, aCTLFontItem ); - aHeight.SetWhich( ATTR_FONT_HEIGHT ); - pData->PutItem( i, aHeight ); - aHeight.SetWhich( ATTR_CJK_FONT_HEIGHT ); - pData->PutItem( i, aHeight ); - aHeight.SetWhich( ATTR_CTL_FONT_HEIGHT ); - pData->PutItem( i, aHeight ); - if (i<4) // top: white on blue - { - pData->PutItem( i, aWhiteText ); - pData->PutItem( i, aBlueBack ); - } - else if ( i%4 == 0 ) // left: white on gray70 - { - pData->PutItem( i, aWhiteText ); - pData->PutItem( i, aGray70Back ); - } - else if ( i%4 == 3 || i >= 12 ) // right and bottom: black on gray20 - { - pData->PutItem( i, aBlackText ); - pData->PutItem( i, aGray20Back ); - } - else // center: black on white - { - pData->PutItem( i, aBlackText ); - pData->PutItem( i, aWhiteBack ); - } + pRet = std::move(*iter); + mpImpl->maAutoFormats.erase(iter); } - - insert(std::move(pData)); + ResetParent(rName); + Save(); + return pRet.release(); } -bool DefaultFirstEntry::operator() (const OUString& left, const OUString& right) const +ScAutoFormatData* ScAutoFormat::FindAutoFormat(const OUString& rName) const { - OUString aStrStandard(ScResId(STR_STYLENAME_STANDARD)); - if (ScGlobal::GetTransliteration().isEqual( left, right ) ) - return false; - if ( ScGlobal::GetTransliteration().isEqual( left, aStrStandard ) ) - return true; - if ( ScGlobal::GetTransliteration().isEqual( right, aStrStandard ) ) - return false; - return ScGlobal::GetCollator().compareString( left, right) < 0; + for (const auto& rFormat : mpImpl->maAutoFormats) + { + if (rFormat->GetName() == rName) + return rFormat.get(); + } + return nullptr; } -void ScAutoFormat::SetSaveLater( bool bSet ) +const ScAutoFormatData* ScAutoFormat::GetResolvedStyle(const SvxAutoFormatData* rData) const { - mbSaveLater = bSet; -} - -const ScAutoFormatData* ScAutoFormat::findByIndex(size_t nIndex) const -{ - if (nIndex >= m_Data.size()) + auto pData = dynamic_cast(rData); + if (!pData) return nullptr; - MapType::const_iterator it = m_Data.begin(); - std::advance(it, nIndex); - return it->second.get(); -} - -ScAutoFormatData* ScAutoFormat::findByIndex(size_t nIndex) -{ - if (nIndex >= m_Data.size()) - return nullptr; - - MapType::iterator it = m_Data.begin(); - std::advance(it, nIndex); - return it->second.get(); -} - -ScAutoFormat::iterator ScAutoFormat::find(const OUString& rName) -{ - return m_Data.find(rName); -} - -ScAutoFormat::iterator ScAutoFormat::insert(std::unique_ptr pNew) -{ - OUString aName = pNew->GetName(); - return m_Data.insert(std::make_pair(aName, std::move(pNew))).first; -} - -void ScAutoFormat::erase(const iterator& it) -{ - m_Data.erase(it); -} - -size_t ScAutoFormat::size() const -{ - return m_Data.size(); -} - -ScAutoFormat::const_iterator ScAutoFormat::begin() const -{ - return m_Data.begin(); -} - -ScAutoFormat::const_iterator ScAutoFormat::end() const -{ - return m_Data.end(); -} - -ScAutoFormat::iterator ScAutoFormat::begin() -{ - return m_Data.begin(); -} - -ScAutoFormat::iterator ScAutoFormat::end() -{ - return m_Data.end(); -} - -void ScAutoFormat::Load() -{ - INetURLObject aURL; - SvtPathOptions aPathOpt; - aURL.SetSmartURL( aPathOpt.GetUserConfigPath() ); - aURL.setFinalSlash(); - aURL.Append( sAutoTblFmtName ); - - SfxMedium aMedium( aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ ); - SvStream* pStream = aMedium.GetInStream(); - bool bRet = (pStream && pStream->GetError() == ERRCODE_NONE); - if (bRet) + if (pData->GetParent().getLength()) { - SvStream& rStream = *pStream; - // Attention: A common header has to be read - sal_uInt16 nVal = 0; - rStream.ReadUInt16( nVal ); - bRet = ERRCODE_NONE == rStream.GetError(); - - if (bRet) + if (auto pParent = GetResolvedStyle(FindAutoFormat(pData->GetParent()))) { - if( nVal == AUTOFORMAT_ID_358 || - (AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) ) - { - sal_uInt8 nChrSet, nCnt; - sal_uInt64 nPos = rStream.Tell(); - rStream.ReadUChar( nCnt ).ReadUChar( nChrSet ); - if( rStream.Tell() != sal_uLong(nPos + nCnt) ) - { - OSL_FAIL( "header contains more/newer data" ); - rStream.Seek( nPos + nCnt ); - } - rStream.SetStreamCharSet( GetSOLoadTextEncoding( nChrSet ) ); - rStream.SetVersion( SOFFICE_FILEFORMAT_40 ); - } - - if( nVal == AUTOFORMAT_ID_358 || nVal == AUTOFORMAT_ID_X || - (AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) ) - { - m_aVersions.Load( rStream, nVal ); // item versions - - sal_uInt16 nCnt = 0; - rStream.ReadUInt16( nCnt ); - bRet = (rStream.GetError() == ERRCODE_NONE); - - // there has to at least be a sal_uInt16 header - const size_t nMaxRecords = rStream.remainingSize() / sizeof(sal_uInt16); - if (nCnt > nMaxRecords) - { - SAL_WARN("sc", "Parsing error: " << nMaxRecords << - " max possible entries, but " << nCnt << " claimed, truncating"); - nCnt = nMaxRecords; - } - - for (sal_uInt16 i=0; bRet && (i < nCnt); i++) - { - std::unique_ptr pData(new ScAutoFormatData()); - bRet = pData->Load(rStream, m_aVersions); - insert(std::move(pData)); - } - } + auto pNew = new ScAutoFormatData(*pData); + pNew->MergeStyle(*pParent); + return pNew; } } - mbSaveLater = false; + + return pData; } -bool ScAutoFormat::Save() -{ - INetURLObject aURL; - SvtPathOptions aPathOpt; - aURL.SetSmartURL( aPathOpt.GetUserConfigPath() ); - aURL.setFinalSlash(); - aURL.Append(sAutoTblFmtName); - - SfxMedium aMedium( aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE ); - SvStream* pStream = aMedium.GetOutStream(); - bool bRet = (pStream && pStream->GetError() == ERRCODE_NONE); - if (bRet) - { - const sal_uInt16 fileVersion = SOFFICE_FILEFORMAT_50; - SvStream& rStream = *pStream; - rStream.SetVersion( fileVersion ); - - // Attention: A common header has to be saved - rStream.WriteUInt16( AUTOFORMAT_ID ) - .WriteUChar( 2 ) // Number of chars of the header including this - .WriteUChar( ::GetSOStoreTextEncoding( - osl_getThreadTextEncoding() ) ); - m_aVersions.Write(rStream, fileVersion); - - bRet &= (rStream.GetError() == ERRCODE_NONE); - - rStream.WriteUInt16( m_Data.size() - 1 ); - bRet &= (rStream.GetError() == ERRCODE_NONE); - MapType::iterator it = m_Data.begin(), itEnd = m_Data.end(); - if (it != itEnd) - { - for (++it; bRet && it != itEnd; ++it) // Skip the first item. - { - bRet &= it->second->Save(rStream, fileVersion); - } - } - - rStream.FlushBuffer(); - - aMedium.Commit(); - } - mbSaveLater = false; - return bRet; -} +size_t ScAutoFormat::size() const { return mpImpl->maAutoFormats.size(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx b/sc/source/ui/attrdlg/scdlgfact.cxx index 8fbd059e1b96..dea44fa52129 100644 --- a/sc/source/ui/attrdlg/scdlgfact.cxx +++ b/sc/source/ui/attrdlg/scdlgfact.cxx @@ -22,7 +22,6 @@ #include "scdlgfact.hxx" #include -#include #include #include #include @@ -139,26 +138,6 @@ VclPtr ScAbstractDialogFactory_Impl::CreateScTex return VclPtr::Create(pParent); } -namespace -{ -class AbstractScAutoFormatDlg_Impl - : public vcl::AbstractDialogImpl_Sync -{ -public: - using AbstractDialogImpl_BASE::AbstractDialogImpl_BASE; - sal_uInt16 GetIndex() const override { return m_pDlg->GetIndex(); } - OUString GetCurrFormatName() override { return m_pDlg->GetCurrFormatName(); } -}; -} - -VclPtr ScAbstractDialogFactory_Impl::CreateScAutoFormatDlg(weld::Window* pParent, - ScAutoFormat* pAutoFormat, - const ScAutoFormatData* pSelFormatData, - ScViewData& rViewData) -{ - return VclPtr::Create(pParent, pAutoFormat, pSelFormatData, rViewData); -} - namespace { class AbstractScColRowLabelDlg_Impl diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx b/sc/source/ui/attrdlg/scdlgfact.hxx index c3bea7a553ee..c1391b7588ba 100644 --- a/sc/source/ui/attrdlg/scdlgfact.hxx +++ b/sc/source/ui/attrdlg/scdlgfact.hxx @@ -34,10 +34,6 @@ public: virtual VclPtr CreateScTextImportOptionsDlg(weld::Window* pParent) override; - virtual VclPtr CreateScAutoFormatDlg(weld::Window* pParent, - ScAutoFormat* pAutoFormat, - const ScAutoFormatData* pSelFormatData, - ScViewData& rViewData) override; virtual VclPtr CreateScColRowLabelDlg (weld::Window* pParent, bool bCol, bool bRow) override; diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index f2ffad81be3c..42372cae96a4 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include #include #include @@ -4326,7 +4327,7 @@ bool ScDocFunc::AutoFormat( const ScRange& rRange, const ScMarkData* pTabMark, { weld::WaitObject aWait( ScDocShell::GetActiveDialogParent() ); - bool bSize = pAutoFormat->findByIndex(nFormatNo)->GetIncludeWidthHeight(); + bool bSize = pAutoFormat->GetData(nFormatNo)->IsWidthHeight(); if (sal_uInt64(nEndCol - nStartCol + 1) * sal_uInt64(nEndRow - nStartRow + 1) > AUTOFORMAT_WARN_SIZE) { std::unique_ptr xQueryBox(Application::CreateMessageDialog(ScDocShell::GetActiveDialogParent(), diff --git a/sc/source/ui/inc/autofmt.hxx b/sc/source/ui/inc/autofmt.hxx deleted file mode 100644 index f4425bdf845b..000000000000 --- a/sc/source/ui/inc/autofmt.hxx +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#pragma once - -#include -#include -#include -#include - -namespace com::sun::star::i18n { class XBreakIterator; } - -class ScAutoFormatData; -class SvxBoxItem; -class SvxLineItem; -class SvNumberFormatter; -class VirtualDevice; -class ScViewData; - -class SC_DLLPUBLIC ScAutoFmtPreview : public weld::CustomWidgetController -{ -public: - ScAutoFmtPreview(); - void DetectRTL(const ScViewData& rViewData); - virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override; - virtual ~ScAutoFmtPreview() override; - - void NotifyChange( ScAutoFormatData* pNewData ); - -protected: - virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; - virtual void Resize() override; - -private: - ScAutoFormatData* pCurData; - ScopedVclPtrInstance aVD; - css::uno::Reference xBreakIter; - bool bFitWidth; - svx::frame::Array maArray; /// Implementation to draw the frame borders. - bool mbRTL; - Size aPrvSize; - tools::Long mnLabelColWidth; - tools::Long mnDataColWidth1; - tools::Long mnDataColWidth2; - tools::Long mnRowHeight; - const OUString aStrJan; - const OUString aStrFeb; - const OUString aStrMar; - const OUString aStrNorth; - const OUString aStrMid; - const OUString aStrSouth; - const OUString aStrSum; - std::unique_ptr pNumFmt; - - SAL_DLLPRIVATE void Init(); - SAL_DLLPRIVATE void DoPaint(vcl::RenderContext& rRenderContext); - SAL_DLLPRIVATE void CalcCellArray(bool bFitWidth); - SAL_DLLPRIVATE void CalcLineMap(); - SAL_DLLPRIVATE void PaintCells(vcl::RenderContext& rRenderContext); - -/* Usage of type size_t instead of SCCOL/SCROW is correct here - used in - conjunction with class svx::frame::Array (svx/framelinkarray.hxx), which - expects size_t coordinates. */ - - SAL_DLLPRIVATE sal_uInt16 GetFormatIndex( size_t nCol, size_t nRow ) const; - SAL_DLLPRIVATE const SvxBoxItem& GetBoxItem( size_t nCol, size_t nRow ) const; - SAL_DLLPRIVATE const SvxLineItem& GetDiagItem( size_t nCol, size_t nRow, bool bTLBR ) const; - - SAL_DLLPRIVATE void DrawString(vcl::RenderContext& rRenderContext, size_t nCol, size_t nRow); - SAL_DLLPRIVATE void DrawBackground(vcl::RenderContext& rRenderContext); - - SAL_DLLPRIVATE void MakeFonts(vcl::RenderContext const& rRenderContext, sal_uInt16 nIndex, - vcl::Font& rFont, vcl::Font& rCJKFont, vcl::Font& rCTLFont); -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/scuiautofmt.hxx b/sc/source/ui/inc/scuiautofmt.hxx deleted file mode 100644 index 129120dd5165..000000000000 --- a/sc/source/ui/inc/scuiautofmt.hxx +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#pragma once - -#include -#include -#include -#include -#include "autofmt.hxx" - -class ScAutoFormatDlg : public weld::GenericDialogController -{ -public: - ScAutoFormatDlg(weld::Window* pParent, - ScAutoFormat* pAutoFormat, - const ScAutoFormatData* pSelFormatData, - const ScViewData& rViewData); - virtual ~ScAutoFormatDlg() override; - - sal_uInt16 GetIndex() const { return m_nIndex; } - OUString GetCurrFormatName(); - -private: - OUString aStrTitle; - OUString aStrLabel; - OUString aStrClose; - OUString aStrDelMsg; - OUString aStrRename; - - ScAutoFormat* pFormat; - const ScAutoFormatData* pSelFmtData; - sal_uInt16 m_nIndex; - bool bCoreDataChanged; - bool bFmtInserted; - - ScAutoFmtPreview m_aWndPreview; - std::unique_ptr m_xLbFormat; - std::unique_ptr m_xBtnOk; - std::unique_ptr m_xBtnCancel; - std::unique_ptr m_xBtnAdd; - std::unique_ptr m_xBtnRemove; - std::unique_ptr m_xBtnRename; - std::unique_ptr m_xBtnNumFormat; - std::unique_ptr m_xBtnBorder; - std::unique_ptr m_xBtnFont; - std::unique_ptr m_xBtnPattern; - std::unique_ptr m_xBtnAlignment; - std::unique_ptr m_xBtnAdjust; - std::unique_ptr m_xWndPreview; - - void Init (); - void UpdateChecks (); - - DECL_LINK( CheckHdl, weld::Toggleable&, void ); - DECL_LINK( AddHdl, weld::Button&, void ); - DECL_LINK( RemoveHdl, weld::Button&, void ); - DECL_LINK( SelFmtHdl, weld::TreeView&, void ); - DECL_LINK( CloseHdl, weld::Button&, void ); - DECL_LINK( DblClkHdl, weld::TreeView&, bool ); - DECL_LINK( RenameHdl, weld::Button&, void ); - -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/miscdlgs/autofmt.cxx b/sc/source/ui/miscdlgs/autofmt.cxx deleted file mode 100644 index dda45d744191..000000000000 --- a/sc/source/ui/miscdlgs/autofmt.cxx +++ /dev/null @@ -1,532 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define FRAME_OFFSET 4 - -// ScAutoFmtPreview - -ScAutoFmtPreview::ScAutoFmtPreview() - : pCurData(nullptr) - , bFitWidth(false) - , mbRTL(false) - , aStrJan(ScResId(STR_JAN)) - , aStrFeb(ScResId(STR_FEB)) - , aStrMar(ScResId(STR_MAR)) - , aStrNorth(ScResId(STR_NORTH)) - , aStrMid(ScResId(STR_MID)) - , aStrSouth(ScResId(STR_SOUTH)) - , aStrSum(ScResId(STR_SUM)) - , pNumFmt(new SvNumberFormatter(::comphelper::getProcessComponentContext(), ScGlobal::eLnge)) -{ - Init(); -} - -void ScAutoFmtPreview::SetDrawingArea(weld::DrawingArea* pDrawingArea) -{ - aVD.disposeAndReset(VclPtr::Create(pDrawingArea->get_ref_device())); - CustomWidgetController::SetDrawingArea(pDrawingArea); -} - -void ScAutoFmtPreview::Resize() -{ - Size aSize(GetOutputSizePixel()); - aPrvSize = Size(aSize.Width() - 6, aSize.Height() - 30); - mnLabelColWidth = (aPrvSize.Width() - 4) / 4 - 12; - mnDataColWidth1 = (aPrvSize.Width() - 4 - 2 * mnLabelColWidth) / 3; - mnDataColWidth2 = (aPrvSize.Width() - 4 - 2 * mnLabelColWidth) / 4; - mnRowHeight = (aPrvSize.Height() - 4) / 5; - NotifyChange(pCurData); -} - -ScAutoFmtPreview::~ScAutoFmtPreview() -{ -} - -static void lcl_SetFontProperties( - vcl::Font& rFont, - const SvxFontItem& rFontItem, - const SvxWeightItem& rWeightItem, - const SvxPostureItem& rPostureItem ) -{ - rFont.SetFamily ( rFontItem.GetFamily() ); - rFont.SetFamilyName ( rFontItem.GetFamilyName() ); - rFont.SetStyleName ( rFontItem.GetStyleName() ); - rFont.SetCharSet ( rFontItem.GetCharSet() ); - rFont.SetPitch ( rFontItem.GetPitch() ); - rFont.SetWeight ( rWeightItem.GetValue() ); - rFont.SetItalic ( rPostureItem.GetValue() ); -} - -void ScAutoFmtPreview::MakeFonts(vcl::RenderContext const& rRenderContext, sal_uInt16 nIndex, vcl::Font& rFont, vcl::Font& rCJKFont, vcl::Font& rCTLFont) -{ - if ( !pCurData ) - return; - - rFont = rCJKFont = rCTLFont = rRenderContext.GetFont(); - Size aFontSize(rFont.GetFontSize().Width(), 10 * rRenderContext.GetDPIScaleFactor()); - - const SvxFontItem* pFontItem = pCurData->GetItem( nIndex, ATTR_FONT ); - const SvxWeightItem* pWeightItem = pCurData->GetItem( nIndex, ATTR_FONT_WEIGHT ); - const SvxPostureItem* pPostureItem = pCurData->GetItem( nIndex, ATTR_FONT_POSTURE ); - const SvxFontItem* pCJKFontItem = pCurData->GetItem( nIndex, ATTR_CJK_FONT ); - const SvxWeightItem* pCJKWeightItem = pCurData->GetItem( nIndex, ATTR_CJK_FONT_WEIGHT ); - const SvxPostureItem* pCJKPostureItem = pCurData->GetItem( nIndex, ATTR_CJK_FONT_POSTURE ); - const SvxFontItem* pCTLFontItem = pCurData->GetItem( nIndex, ATTR_CTL_FONT ); - const SvxWeightItem* pCTLWeightItem = pCurData->GetItem( nIndex, ATTR_CTL_FONT_WEIGHT ); - const SvxPostureItem* pCTLPostureItem = pCurData->GetItem( nIndex, ATTR_CTL_FONT_POSTURE ); - const SvxUnderlineItem* pUnderlineItem = pCurData->GetItem( nIndex, ATTR_FONT_UNDERLINE ); - const SvxOverlineItem* pOverlineItem = pCurData->GetItem( nIndex, ATTR_FONT_OVERLINE ); - const SvxCrossedOutItem* pCrossedOutItem = pCurData->GetItem( nIndex, ATTR_FONT_CROSSEDOUT ); - const SvxContourItem* pContourItem = pCurData->GetItem( nIndex, ATTR_FONT_CONTOUR ); - const SvxShadowedItem* pShadowedItem = pCurData->GetItem( nIndex, ATTR_FONT_SHADOWED ); - const SvxColorItem* pColorItem = pCurData->GetItem( nIndex, ATTR_FONT_COLOR ); - - lcl_SetFontProperties( rFont, *pFontItem, *pWeightItem, *pPostureItem ); - lcl_SetFontProperties( rCJKFont, *pCJKFontItem, *pCJKWeightItem, *pCJKPostureItem ); - lcl_SetFontProperties( rCTLFont, *pCTLFontItem, *pCTLWeightItem, *pCTLPostureItem ); - - Color aColor( pColorItem->GetValue() ); - if( aColor == COL_TRANSPARENT ) - aColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor(); - -#define SETONALLFONTS( MethodName, Value ) \ -rFont.MethodName( Value ); rCJKFont.MethodName( Value ); rCTLFont.MethodName( Value ); - - SETONALLFONTS( SetUnderline, pUnderlineItem->GetValue() ) - SETONALLFONTS( SetOverline, pOverlineItem->GetValue() ) - SETONALLFONTS( SetStrikeout, pCrossedOutItem->GetValue() ) - SETONALLFONTS( SetOutline, pContourItem->GetValue() ) - SETONALLFONTS( SetShadow, pShadowedItem->GetValue() ) - SETONALLFONTS( SetColor, aColor ) - SETONALLFONTS( SetFontSize, aFontSize ) - SETONALLFONTS( SetTransparent, true ) - -#undef SETONALLFONTS -} - -sal_uInt16 ScAutoFmtPreview::GetFormatIndex( size_t nCol, size_t nRow ) const -{ - static const sal_uInt16 pnFmtMap[] = - { - 0, 1, 2, 1, 3, - 4, 5, 6, 5, 7, - 8, 9, 10, 9, 11, - 4, 5, 6, 5, 7, - 12, 13, 14, 13, 15 - }; - return pnFmtMap[ maArray.GetCellIndex( nCol, nRow, mbRTL ) ]; -} - -const SvxBoxItem& ScAutoFmtPreview::GetBoxItem( size_t nCol, size_t nRow ) const -{ - assert(pCurData && "ScAutoFmtPreview::GetBoxItem - no format data found"); - return * pCurData->GetItem( GetFormatIndex( nCol, nRow ), ATTR_BORDER ); -} - -const SvxLineItem& ScAutoFmtPreview::GetDiagItem( size_t nCol, size_t nRow, bool bTLBR ) const -{ - assert(pCurData && "ScAutoFmtPreview::GetDiagItem - no format data found"); - return * pCurData->GetItem( GetFormatIndex( nCol, nRow ), bTLBR ? ATTR_BORDER_TLBR : ATTR_BORDER_BLTR ); -} - -void ScAutoFmtPreview::DrawString(vcl::RenderContext& rRenderContext, size_t nCol, size_t nRow) -{ - if (!pCurData) - { - return; - } - - // Emit the cell text - - OUString cellString; - bool bNumFormat = pCurData->GetIncludeValueFormat(); - sal_uInt32 nNum; - double nVal; - const Color* pDummy = nullptr; - sal_uInt16 nIndex = static_cast(maArray.GetCellIndex(nCol, nRow, mbRTL)); - - switch (nIndex) - { - case 1: cellString = aStrJan; break; - case 2: cellString = aStrFeb; break; - case 3: cellString = aStrMar; break; - case 5: cellString = aStrNorth; break; - case 10: cellString = aStrMid; break; - case 15: cellString = aStrSouth; break; - case 4: - case 20: cellString = aStrSum; break; - - case 6: - case 8: - case 16: - case 18: nVal = nIndex; - nNum = 5; - goto mknum; - case 17: - case 7: nVal = nIndex; - nNum = 6; - goto mknum; - case 11: - case 12: - case 13: nVal = nIndex; - nNum = 12 == nIndex ? 10 : 9; - goto mknum; - - case 9: nVal = 21; nNum = 7; goto mknum; - case 14: nVal = 36; nNum = 11; goto mknum; - case 19: nVal = 51; nNum = 7; goto mknum; - case 21: nVal = 33; nNum = 13; goto mknum; - case 22: nVal = 36; nNum = 14; goto mknum; - case 23: nVal = 39; nNum = 13; goto mknum; - case 24: nVal = 108; nNum = 15; - mknum: - if (bNumFormat) - { - ScNumFormatAbbrev& rNumFormat = const_cast(pCurData->GetNumFormat(sal_uInt16(nNum))); - nNum = rNumFormat.GetFormatIndex(*pNumFmt); - } - else - nNum = 0; - pNumFmt->GetOutputString(nVal, nNum, cellString, &pDummy); - break; - } - - if (cellString.isEmpty()) - return; - - Size aStrSize; - sal_uInt16 nFmtIndex = GetFormatIndex( nCol, nRow ); - const basegfx::B2DRange cellRange(maArray.GetCellRange( nCol, nRow )); - Point aPos(basegfx::fround(cellRange.getMinX()), basegfx::fround(cellRange.getMinY())); - sal_uInt16 nRightX = 0; - bool bJustify = pCurData->GetIncludeJustify(); - SvxCellHorJustify eJustification; - - SvtScriptedTextHelper aScriptedText(rRenderContext); - - // Justification: - - eJustification = mbRTL ? SvxCellHorJustify::Right : bJustify ? - pCurData->GetItem(nFmtIndex, ATTR_HOR_JUSTIFY)->GetValue() : - SvxCellHorJustify::Standard; - - if (pCurData->GetIncludeFont()) - { - vcl::Font aFont, aCJKFont, aCTLFont; - Size theMaxStrSize; - - MakeFonts(rRenderContext, nFmtIndex, aFont, aCJKFont, aCTLFont); - - theMaxStrSize = Size(basegfx::fround(cellRange.getWidth()), basegfx::fround(cellRange.getHeight())); - theMaxStrSize.AdjustWidth( -(FRAME_OFFSET) ); - theMaxStrSize.AdjustHeight( -(FRAME_OFFSET) ); - - aScriptedText.SetFonts( &aFont, &aCJKFont, &aCTLFont ); - aScriptedText.SetText(cellString, xBreakIter); - aStrSize = aScriptedText.GetTextSize(); - - if (theMaxStrSize.Height() < aStrSize.Height()) - { - // if the string does not fit in the row using this font, - // the default font is used - aScriptedText.SetDefaultFont(); - aStrSize = aScriptedText.GetTextSize(); - } - while((theMaxStrSize.Width() <= aStrSize.Width()) && (cellString.getLength() > 1)) - { - if( eJustification == SvxCellHorJustify::Right ) - cellString = cellString.copy(1); - else - cellString = cellString.copy(0, cellString.getLength() - 1 ); - - aScriptedText.SetText( cellString, xBreakIter ); - aStrSize = aScriptedText.GetTextSize(); - } - } - else - { - aScriptedText.SetDefaultFont(); - aScriptedText.SetText( cellString, xBreakIter ); - aStrSize = aScriptedText.GetTextSize(); - } - - nRightX = sal_uInt16(basegfx::fround(cellRange.getWidth()) - aStrSize.Width() - FRAME_OFFSET); - - // vertical (always center): - - aPos.AdjustY((mnRowHeight - static_cast(aStrSize.Height())) / 2 ); - - // horizontal - - if (eJustification != SvxCellHorJustify::Standard) - { - sal_uInt16 nHorPos = sal_uInt16((basegfx::fround(cellRange.getWidth())-aStrSize.Width()) / 2); - //sal_uInt16 nHorPos = sal_uInt16((basegfx::fround(cellRange.getWidth())-aStrSize.Width()) / 2); - - switch (eJustification) - { - case SvxCellHorJustify::Left: - aPos.AdjustX(FRAME_OFFSET ); - break; - case SvxCellHorJustify::Right: - aPos.AdjustX(nRightX ); - break; - case SvxCellHorJustify::Block: - case SvxCellHorJustify::Repeat: - case SvxCellHorJustify::Center: - aPos.AdjustX(nHorPos ); - break; - // coverity[dead_error_line] - following conditions exist to avoid compiler warning - case SvxCellHorJustify::Standard: - default: - // Standard is not handled here - break; - } - } - else - { - - // Standard justification - - if (nCol == 0 || nRow == 0) - { - // Text label to the left or sum left adjusted - aPos.AdjustX(FRAME_OFFSET ); - } - else - { - // Numbers/Dates right adjusted - aPos.AdjustX(nRightX ); - } - } - aScriptedText.DrawText(aPos); -} - -#undef FRAME_OFFSET - -void ScAutoFmtPreview::DrawBackground(vcl::RenderContext& rRenderContext) -{ - if (!pCurData) - return; - - for(size_t nRow = 0; nRow < 5; ++nRow) - { - for(size_t nCol = 0; nCol < 5; ++nCol) - { - const SvxBrushItem* pItem = - pCurData->GetItem( GetFormatIndex( nCol, nRow ), ATTR_BACKGROUND ); - - auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR); - rRenderContext.SetLineColor(); - if (pItem->GetColor() == COL_TRANSPARENT) - rRenderContext.SetFillColor(); - else - rRenderContext.SetFillColor( pItem->GetColor() ); - - const basegfx::B2DRange aCellRange(maArray.GetCellRange( nCol, nRow )); - rRenderContext.DrawRect( - tools::Rectangle( - basegfx::fround(aCellRange.getMinX()), basegfx::fround(aCellRange.getMinY()), - basegfx::fround(aCellRange.getMaxX()), basegfx::fround(aCellRange.getMaxY()))); - - } - } -} - -void ScAutoFmtPreview::PaintCells(vcl::RenderContext& rRenderContext) -{ - if (!pCurData) - return; - - // 1) background - if (pCurData->GetIncludeBackground()) - DrawBackground(rRenderContext); - - // 2) values - for(size_t nRow = 0; nRow < 5; ++nRow) - for(size_t nCol = 0; nCol < 5; ++nCol) - DrawString(rRenderContext, nCol, nRow); - - // 3) border - if (!pCurData->GetIncludeFrame()) - return; - - const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D; - std::unique_ptr pProcessor2D( - drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice( - rRenderContext, - aNewViewInformation2D)); - - pProcessor2D->process(maArray.CreateB2DPrimitiveArray()); - pProcessor2D.reset(); -} - -void ScAutoFmtPreview::Init() -{ - maArray.Initialize( 5, 5 ); - mnLabelColWidth = 0; - mnDataColWidth1 = 0; - mnDataColWidth2 = 0; - mnRowHeight = 0; - CalcCellArray( false ); - CalcLineMap(); -} - -void ScAutoFmtPreview::DetectRTL(const ScViewData& rViewData) -{ - SCTAB nCurrentTab = rViewData.CurrentTabForData(); - ScDocument& rDoc = rViewData.GetDocument(); - mbRTL = rDoc.IsLayoutRTL(nCurrentTab); - xBreakIter = rDoc.GetBreakIterator(); -} - -void ScAutoFmtPreview::CalcCellArray( bool bFitWidthP ) -{ - maArray.SetXOffset( 2 ); - maArray.SetAllColWidths( bFitWidthP ? mnDataColWidth2 : mnDataColWidth1 ); - maArray.SetColWidth( 0, mnLabelColWidth ); - maArray.SetColWidth( 4, mnLabelColWidth ); - - maArray.SetYOffset( 2 ); - maArray.SetAllRowHeights( mnRowHeight ); - - aPrvSize.setWidth( maArray.GetWidth() + 4 ); - aPrvSize.setHeight( maArray.GetHeight() + 4 ); -} - -static void lclSetStyleFromBorder( svx::frame::Style& rStyle, const ::editeng::SvxBorderLine* pBorder ) -{ - rStyle.Set(pBorder, o3tl::convert(1.0, o3tl::Length::twip, o3tl::Length::pt), 5); -} - -void ScAutoFmtPreview::CalcLineMap() -{ - if ( !pCurData ) - return; - - for( size_t nRow = 0; nRow < 5; ++nRow ) - { - for( size_t nCol = 0; nCol < 5; ++nCol ) - { - svx::frame::Style aStyle; - - const SvxBoxItem& rItem = GetBoxItem( nCol, nRow ); - lclSetStyleFromBorder( aStyle, rItem.GetLeft() ); - maArray.SetCellStyleLeft( nCol, nRow, aStyle ); - lclSetStyleFromBorder( aStyle, rItem.GetRight() ); - maArray.SetCellStyleRight( nCol, nRow, aStyle ); - lclSetStyleFromBorder( aStyle, rItem.GetTop() ); - maArray.SetCellStyleTop( nCol, nRow, aStyle ); - lclSetStyleFromBorder( aStyle, rItem.GetBottom() ); - maArray.SetCellStyleBottom( nCol, nRow, aStyle ); - - lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, true ).GetLine() ); - maArray.SetCellStyleTLBR( nCol, nRow, aStyle ); - lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, false ).GetLine() ); - maArray.SetCellStyleBLTR( nCol, nRow, aStyle ); - } - } -} - -void ScAutoFmtPreview::NotifyChange( ScAutoFormatData* pNewData ) -{ - if (pNewData) - { - pCurData = pNewData; - bFitWidth = pNewData->GetIncludeWidthHeight(); - } - - CalcCellArray( bFitWidth ); - CalcLineMap(); - - Invalidate(); -} - -void ScAutoFmtPreview::DoPaint(vcl::RenderContext& rRenderContext) -{ - auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::ALL); - DrawModeFlags nOldDrawMode = aVD->GetDrawMode(); - - Size aWndSize(GetOutputSizePixel()); - vcl::Font aFont(aVD->GetFont()); - const Color& aBackCol = ScModule::get()->GetColorConfig().GetColorValue( ::svtools::DOCCOLOR ).nColor; - tools::Rectangle aRect(Point(), aWndSize); - - aFont.SetTransparent( true ); - aVD->SetFont(aFont); - aVD->SetLineColor(); - aVD->SetFillColor(aBackCol); - aVD->SetOutputSize(aWndSize); - aVD->DrawRect(aRect); - - PaintCells(*aVD); - - rRenderContext.SetLineColor(); - rRenderContext.SetFillColor(aBackCol); - rRenderContext.DrawRect(aRect); - - Point aPos((aWndSize.Width() - aPrvSize.Width()) / 2, (aWndSize.Height() - aPrvSize.Height()) / 2); - if (AllSettings::GetLayoutRTL()) - aPos.setX( -aPos.X() ); - rRenderContext.DrawOutDev(aPos, aWndSize, Point(), aWndSize, *aVD); - aVD->SetDrawMode(nOldDrawMode); -} - -void ScAutoFmtPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/) -{ - DoPaint(rRenderContext); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/miscdlgs/scuiautofmt.cxx b/sc/source/ui/miscdlgs/scuiautofmt.cxx deleted file mode 100644 index 622149f86e83..000000000000 --- a/sc/source/ui/miscdlgs/scuiautofmt.cxx +++ /dev/null @@ -1,389 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#undef SC_DLLIMPLEMENTATION - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// AutoFormat-Dialog: - -ScAutoFormatDlg::ScAutoFormatDlg(weld::Window* pParent, - ScAutoFormat* pAutoFormat, - const ScAutoFormatData* pSelFormatData, - const ScViewData& rViewData) - : GenericDialogController(pParent, u"modules/scalc/ui/autoformattable.ui"_ustr, u"AutoFormatTableDialog"_ustr) - , aStrTitle(ScResId(STR_ADD_AUTOFORMAT_TITLE)) - , aStrLabel(ScResId(STR_ADD_AUTOFORMAT_LABEL)) - , aStrClose(ScResId(STR_BTN_AUTOFORMAT_CLOSE)) - , aStrDelMsg(ScResId(STR_DEL_AUTOFORMAT_MSG)) - , aStrRename(ScResId(STR_RENAME_AUTOFORMAT_TITLE)) - , pFormat(pAutoFormat) - , pSelFmtData(pSelFormatData) - , m_nIndex(0) - , bCoreDataChanged(false) - , bFmtInserted(false) - , m_xLbFormat(m_xBuilder->weld_tree_view(u"formatlb"_ustr)) - , m_xBtnOk(m_xBuilder->weld_button(u"ok"_ustr)) - , m_xBtnCancel(m_xBuilder->weld_button(u"cancel"_ustr)) - , m_xBtnAdd(m_xBuilder->weld_button(u"add"_ustr)) - , m_xBtnRemove(m_xBuilder->weld_button(u"remove"_ustr)) - , m_xBtnRename(m_xBuilder->weld_button(u"rename"_ustr)) - , m_xBtnNumFormat(m_xBuilder->weld_check_button(u"numformatcb"_ustr)) - , m_xBtnBorder(m_xBuilder->weld_check_button(u"bordercb"_ustr)) - , m_xBtnFont(m_xBuilder->weld_check_button(u"fontcb"_ustr)) - , m_xBtnPattern(m_xBuilder->weld_check_button(u"patterncb"_ustr)) - , m_xBtnAlignment(m_xBuilder->weld_check_button(u"alignmentcb"_ustr)) - , m_xBtnAdjust(m_xBuilder->weld_check_button(u"autofitcb"_ustr)) - , m_xWndPreview(new weld::CustomWeld(*m_xBuilder, u"preview"_ustr, m_aWndPreview)) -{ - m_aWndPreview.DetectRTL(rViewData); - - const int nWidth = m_xLbFormat->get_approximate_digit_width() * 32; - const int nHeight = m_xLbFormat->get_height_rows(8); - m_xLbFormat->set_size_request(nWidth, nHeight); - m_xWndPreview->set_size_request(nWidth, nHeight); - - Init(); - ScAutoFormat::iterator it = pFormat->begin(); - m_aWndPreview.NotifyChange(it->second.get()); -} - -ScAutoFormatDlg::~ScAutoFormatDlg() -{ -} - -void ScAutoFormatDlg::Init() -{ - m_xLbFormat->connect_selection_changed(LINK(this, ScAutoFormatDlg, SelFmtHdl)); - m_xBtnNumFormat->connect_toggled( LINK( this, ScAutoFormatDlg, CheckHdl ) ); - m_xBtnBorder->connect_toggled( LINK( this, ScAutoFormatDlg, CheckHdl ) ); - m_xBtnFont->connect_toggled( LINK( this, ScAutoFormatDlg, CheckHdl ) ); - m_xBtnPattern->connect_toggled( LINK( this, ScAutoFormatDlg, CheckHdl ) ); - m_xBtnAlignment->connect_toggled( LINK( this, ScAutoFormatDlg, CheckHdl ) ); - m_xBtnAdjust->connect_toggled( LINK( this, ScAutoFormatDlg, CheckHdl ) ); - m_xBtnAdd->connect_clicked ( LINK( this, ScAutoFormatDlg, AddHdl ) ); - m_xBtnRemove->connect_clicked ( LINK( this, ScAutoFormatDlg, RemoveHdl ) ); - m_xBtnOk->connect_clicked ( LINK( this, ScAutoFormatDlg, CloseHdl ) ); - m_xBtnCancel->connect_clicked ( LINK( this, ScAutoFormatDlg, CloseHdl ) ); - m_xBtnRename->connect_clicked ( LINK( this, ScAutoFormatDlg, RenameHdl ) ); - m_xLbFormat->connect_row_activated( LINK( this, ScAutoFormatDlg, DblClkHdl ) ); - - for (const auto& rEntry : *pFormat) - m_xLbFormat->append_text(rEntry.second->GetName()); - - if (pFormat->size() == 1) - m_xBtnRemove->set_sensitive(false); - - m_xLbFormat->select(0); - m_xBtnRename->set_sensitive(false); - m_xBtnRemove->set_sensitive(false); - - m_nIndex = 0; - UpdateChecks(); - - if ( !pSelFmtData ) - { - m_xBtnAdd->set_sensitive(false); - m_xBtnRemove->set_sensitive(false); - bFmtInserted = true; - } -} - -void ScAutoFormatDlg::UpdateChecks() -{ - const ScAutoFormatData* pData = pFormat->findByIndex(m_nIndex); - - m_xBtnNumFormat->set_active( pData->GetIncludeValueFormat() ); - m_xBtnBorder->set_active( pData->GetIncludeFrame() ); - m_xBtnFont->set_active( pData->GetIncludeFont() ); - m_xBtnPattern->set_active( pData->GetIncludeBackground() ); - m_xBtnAlignment->set_active( pData->GetIncludeJustify() ); - m_xBtnAdjust->set_active( pData->GetIncludeWidthHeight() ); -} - -// Handler: - -IMPL_LINK(ScAutoFormatDlg, CloseHdl, weld::Button&, rBtn, void) -{ - if (&rBtn == m_xBtnOk.get() || &rBtn == m_xBtnCancel.get()) - { - if ( bCoreDataChanged ) - ScGlobal::GetOrCreateAutoFormat()->Save(); - - m_xDialog->response( (&rBtn == m_xBtnOk.get()) ? RET_OK : RET_CANCEL ); - } -} - -IMPL_LINK_NOARG(ScAutoFormatDlg, DblClkHdl, weld::TreeView&, bool) -{ - if ( bCoreDataChanged ) - ScGlobal::GetOrCreateAutoFormat()->Save(); - - m_xDialog->response( RET_OK ); - - return true; -} - -IMPL_LINK(ScAutoFormatDlg, CheckHdl, weld::Toggleable&, rBtn, void) -{ - ScAutoFormatData* pData = pFormat->findByIndex(m_nIndex); - bool bCheck = rBtn.get_active(); - - if (&rBtn == m_xBtnNumFormat.get()) - pData->SetIncludeValueFormat( bCheck ); - else if (&rBtn == m_xBtnBorder.get()) - pData->SetIncludeFrame( bCheck ); - else if (&rBtn == m_xBtnFont.get()) - pData->SetIncludeFont( bCheck ); - else if (&rBtn == m_xBtnPattern.get()) - pData->SetIncludeBackground( bCheck ); - else if (&rBtn == m_xBtnAlignment.get()) - pData->SetIncludeJustify( bCheck ); - else if (&rBtn == m_xBtnAdjust.get()) - pData->SetIncludeWidthHeight( bCheck ); - - if ( !bCoreDataChanged ) - { - m_xBtnCancel->set_label(aStrClose); - bCoreDataChanged = true; - } - - m_aWndPreview.NotifyChange( pData ); -} - -IMPL_LINK_NOARG(ScAutoFormatDlg, AddHdl, weld::Button&, void) -{ - if ( bFmtInserted || !pSelFmtData ) - return; - - OUString aStrStandard( SfxResId(STR_STANDARD) ); - OUString aFormatName; - bool bOk = false; - - while ( !bOk ) - { - ScStringInputDlg aDlg(m_xDialog.get(), aStrTitle, aStrLabel, aFormatName, - HID_SC_ADD_AUTOFMT, HID_SC_AUTOFMT_NAME); - - if (aDlg.run() == RET_OK) - { - aFormatName = aDlg.GetInputString(); - - if ( !aFormatName.isEmpty() && aFormatName != aStrStandard && pFormat->find(aFormatName) == pFormat->end() ) - { - std::unique_ptr pNewData( - new ScAutoFormatData( *pSelFmtData )); - - pNewData->SetName( aFormatName ); - ScAutoFormat::iterator it = pFormat->insert(std::move(pNewData)); - bFmtInserted = it != pFormat->end(); - - if ( bFmtInserted ) - { - size_t nPos = std::distance(pFormat->begin(), it); - m_xLbFormat->insert_text(nPos, aFormatName); - m_xLbFormat->select_text( aFormatName ); - m_xBtnAdd->set_sensitive(false); - - if ( !bCoreDataChanged ) - { - m_xBtnCancel->set_label( aStrClose ); - bCoreDataChanged = true; - } - - SelFmtHdl( *m_xLbFormat ); - bOk = true; - } - } - - if ( !bFmtInserted ) - { - std::unique_ptr xBox(Application::CreateMessageDialog(m_xDialog.get(), - VclMessageType::Error, VclButtonsType::OkCancel, - ScResId(STR_INVALID_AFNAME))); - - sal_uInt16 nRet = xBox->run(); - - bOk = ( nRet == RET_CANCEL ); - } - } - else - bOk = true; - } -} - -IMPL_LINK_NOARG(ScAutoFormatDlg, RemoveHdl, weld::Button&, void) -{ - if ( (m_nIndex > 0) && (m_xLbFormat->n_children() > 0) ) - { - OUString aMsg = o3tl::getToken(aStrDelMsg, 0, '#' ) - + m_xLbFormat->get_selected_text() - + o3tl::getToken(aStrDelMsg, 1, '#' ); - - std::unique_ptr xQueryBox(Application::CreateMessageDialog(m_xDialog.get(), - VclMessageType::Question, VclButtonsType::YesNo, - aMsg)); - xQueryBox->set_default_response(RET_YES); - - if (RET_YES == xQueryBox->run()) - { - m_xLbFormat->remove(m_nIndex); - m_xLbFormat->select(m_nIndex-1); - - if ( m_nIndex-1 == 0 ) - m_xBtnRemove->set_sensitive(false); - - if ( !bCoreDataChanged ) - { - m_xBtnCancel->set_label( aStrClose ); - bCoreDataChanged = true; - } - - ScAutoFormat::iterator it = pFormat->begin(); - std::advance(it, m_nIndex); - pFormat->erase(it); - m_nIndex--; - - SelFmtHdl( *m_xLbFormat ); - } - } - - SelFmtHdl( *m_xLbFormat ); -} - -IMPL_LINK_NOARG(ScAutoFormatDlg, RenameHdl, weld::Button&, void) -{ - bool bOk = false; - while( !bOk ) - { - - OUString aFormatName = m_xLbFormat->get_selected_text(); - OUString aEntry; - - ScStringInputDlg aDlg(m_xDialog.get(), aStrRename, aStrLabel, aFormatName, - HID_SC_REN_AFMT_DLG, HID_SC_REN_AFMT_NAME); - if (aDlg.run() == RET_OK) - { - bool bFmtRenamed = false; - aFormatName = aDlg.GetInputString(); - - if (!aFormatName.isEmpty()) - { - ScAutoFormat::iterator it = pFormat->begin(), itEnd = pFormat->end(); - for (; it != itEnd; ++it) - { - aEntry = it->second->GetName(); - if (aFormatName == aEntry) - break; - } - if (it == itEnd) - { - // no format with this name yet, so we can rename - - m_xLbFormat->remove(m_nIndex); - const ScAutoFormatData* p = pFormat->findByIndex(m_nIndex); - std::unique_ptr pNewData(new ScAutoFormatData(*p)); - - it = pFormat->begin(); - std::advance(it, m_nIndex); - pFormat->erase(it); - - pNewData->SetName( aFormatName ); - - pFormat->insert(std::move(pNewData)); - - m_xLbFormat->freeze(); - m_xLbFormat->clear(); - for (it = pFormat->begin(); it != itEnd; ++it) - { - aEntry = it->second->GetName(); - m_xLbFormat->append_text(aEntry); - } - - m_xLbFormat->thaw(); - m_xLbFormat->select_text(aFormatName); - - if ( !bCoreDataChanged ) - { - m_xBtnCancel->set_label( aStrClose ); - bCoreDataChanged = true; - } - - SelFmtHdl( *m_xLbFormat ); - bOk = true; - bFmtRenamed = true; - } - } - if( !bFmtRenamed ) - { - std::unique_ptr xBox(Application::CreateMessageDialog(m_xDialog.get(), - VclMessageType::Error, VclButtonsType::OkCancel, - ScResId(STR_INVALID_AFNAME))); - - bOk = RET_CANCEL == xBox->run(); - } - } - else - bOk = true; - } -} - -IMPL_LINK_NOARG(ScAutoFormatDlg, SelFmtHdl, weld::TreeView&, void) -{ - int nIndex = m_xLbFormat->get_selected_index(); - assert(nIndex != -1 && "nothing selected"); - m_nIndex = nIndex; - UpdateChecks(); - - if ( m_nIndex == 0 ) - { - m_xBtnRename->set_sensitive(false); - m_xBtnRemove->set_sensitive(false); - } - else - { - m_xBtnRename->set_sensitive(true); - m_xBtnRemove->set_sensitive(true); - } - - ScAutoFormatData* p = pFormat->findByIndex(m_nIndex); - m_aWndPreview.NotifyChange(p); -} - -OUString ScAutoFormatDlg::GetCurrFormatName() -{ - const ScAutoFormatData* p = pFormat->findByIndex(m_nIndex); - return p ? p->GetName() : OUString(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/unoobj/afmtuno.cxx b/sc/source/ui/unoobj/afmtuno.cxx index cae8c2339d52..704721b33d6f 100644 --- a/sc/source/ui/unoobj/afmtuno.cxx +++ b/sc/source/ui/unoobj/afmtuno.cxx @@ -126,17 +126,15 @@ SC_SIMPLE_SERVICE_INFO( ScAutoFormatFieldObj, u"ScAutoFormatFieldObj"_ustr, u"co SC_SIMPLE_SERVICE_INFO( ScAutoFormatObj, u"ScAutoFormatObj"_ustr, u"com.sun.star.sheet.TableAutoFormat"_ustr ) SC_SIMPLE_SERVICE_INFO( ScAutoFormatsObj, u"stardiv.StarCalc.ScAutoFormatsObj"_ustr, SCAUTOFORMATSOBJ_SERVICE ) -static bool lcl_FindAutoFormatIndex( const ScAutoFormat& rFormats, std::u16string_view rName, sal_uInt16& rOutIndex ) +static bool lcl_FindAutoFormatIndex(const ScAutoFormat& rFormats, std::u16string_view rName, + sal_uInt16& rOutIndex) { - ScAutoFormat::const_iterator itBeg = rFormats.begin(), itEnd = rFormats.end(); - for (ScAutoFormat::const_iterator it = itBeg; it != itEnd; ++it) + for (size_t i = 0; i < rFormats.size(); i++) { - const ScAutoFormatData *const pEntry = it->second.get(); - const OUString& aEntryName = pEntry->GetName(); - if ( aEntryName == rName ) + const ScAutoFormatData* pData = rFormats.GetData(i); + if (pData->GetName() == rName) { - size_t nPos = std::distance(itBeg, it); - rOutIndex = nPos; + rOutIndex = i; return true; } } @@ -201,10 +199,10 @@ void SAL_CALL ScAutoFormatsObj::insertByName( const OUString& aName, const uno:: throw container::ElementExistException(); } - std::unique_ptr pNew(new ScAutoFormatData()); + ScAutoFormatData* pNew = new ScAutoFormatData(); pNew->SetName( aName ); - if (pFormats->insert(std::move(pNew)) != pFormats->end()) + if (pFormats->InsertAutoFormat(pNew)) { //! notify to other objects pFormats->Save(); @@ -215,6 +213,8 @@ void SAL_CALL ScAutoFormatsObj::insertByName( const OUString& aName, const uno:: pFormatObj->InitFormat( nNewIndex ); // can be used now bDone = true; } + + ScGlobal::ResetAutoFormat(); } else { @@ -243,17 +243,16 @@ void SAL_CALL ScAutoFormatsObj::removeByName( const OUString& aName ) { SolarMutexGuard aGuard; ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat(); - - ScAutoFormat::iterator it = pFormats->find(aName); - if (it == pFormats->end()) + ScAutoFormatData* pData = pFormats->FindAutoFormat(aName); + if (!pData) { throw container::NoSuchElementException(); } - pFormats->erase(it); + pFormats->ReleaseAutoFormat(aName); //! notify to other objects pFormats->Save(); // save immediately - + ScGlobal::ResetAutoFormat(); } // container::XEnumerationAccess @@ -309,11 +308,11 @@ uno::Sequence SAL_CALL ScAutoFormatsObj::getElementNames() ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat(); uno::Sequence aSeq(pFormats->size()); OUString* pAry = aSeq.getArray(); - size_t i = 0; - for (const auto& rEntry : *pFormats) + for (size_t i = 0; i < pFormats->size(); i++) { - pAry[i] = rEntry.second->GetName(); - ++i; + ScAutoFormatData* pData = pFormats->GetData(i); + if (pData) + pAry[i] = pData->GetName(); } return aSeq; } @@ -321,9 +320,8 @@ uno::Sequence SAL_CALL ScAutoFormatsObj::getElementNames() sal_Bool SAL_CALL ScAutoFormatsObj::hasByName( const OUString& aName ) { SolarMutexGuard aGuard; - sal_uInt16 nDummy; - return lcl_FindAutoFormatIndex( - *ScGlobal::GetOrCreateAutoFormat(), aName, nDummy ); + auto pData = ScGlobal::GetOrCreateAutoFormat()->FindAutoFormat(aName); + return pData ? true : false; } ScAutoFormatObj::ScAutoFormatObj(sal_uInt16 nIndex) : @@ -334,17 +332,6 @@ ScAutoFormatObj::ScAutoFormatObj(sal_uInt16 nIndex) : ScAutoFormatObj::~ScAutoFormatObj() { - // If an AutoFormat object is released, then eventually changes are saved - // so that they become visible in e.g Writer - - if (IsInserted()) - { - ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); - if ( pFormats && pFormats->IsSaveLater() ) - pFormats->Save(); - - // Save() resets flag SaveLater - } } void ScAutoFormatObj::InitFormat( sal_uInt16 nNewIndex ) @@ -412,7 +399,7 @@ OUString SAL_CALL ScAutoFormatObj::getName() SolarMutexGuard aGuard; ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat(); if (IsInserted() && nFormatIndex < pFormats->size()) - return pFormats->findByIndex(nFormatIndex)->GetName(); + return pFormats->GetData(nFormatIndex)->GetName(); return OUString(); } @@ -430,23 +417,9 @@ void SAL_CALL ScAutoFormatObj::setName( const OUString& aNewName ) throw uno::RuntimeException(); } - ScAutoFormat::iterator it = pFormats->begin(); - std::advance(it, nFormatIndex); - ScAutoFormatData *const pData = it->second.get(); - assert(pData && "AutoFormat data not available"); - - std::unique_ptr pNew(new ScAutoFormatData(*pData)); - pNew->SetName( aNewName ); - - pFormats->erase(it); - it = pFormats->insert(std::move(pNew)); - if (it != pFormats->end()) + if (ScAutoFormatData* pData = pFormats->GetData(nFormatIndex)) { - ScAutoFormat::iterator itBeg = pFormats->begin(); - nFormatIndex = std::distance(itBeg, it); - - //! notify to other objects - pFormats->SetSaveLater(true); + pData->SetName(aNewName); } else { @@ -472,27 +445,27 @@ void SAL_CALL ScAutoFormatObj::setPropertyValue( if (!(IsInserted() && nFormatIndex < pFormats->size())) return; - ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex); + ScAutoFormatData* pData = pFormats->GetData(nFormatIndex); OSL_ENSURE(pData,"AutoFormat data not available"); bool bBool = false; if (aPropertyName == SC_UNONAME_INCBACK && (aValue >>= bBool)) - pData->SetIncludeBackground( bBool ); + pData->SetBackground( bBool ); else if (aPropertyName == SC_UNONAME_INCBORD && (aValue >>= bBool)) - pData->SetIncludeFrame( bBool ); + pData->SetFrame( bBool ); else if (aPropertyName == SC_UNONAME_INCFONT && (aValue >>= bBool)) - pData->SetIncludeFont( bBool ); + pData->SetFont( bBool ); else if (aPropertyName == SC_UNONAME_INCJUST && (aValue >>= bBool)) - pData->SetIncludeJustify( bBool ); + pData->SetJustify( bBool ); else if (aPropertyName == SC_UNONAME_INCNUM && (aValue >>= bBool)) - pData->SetIncludeValueFormat( bBool ); + pData->SetValueFormat( bBool ); else if (aPropertyName == SC_UNONAME_INCWIDTH && (aValue >>= bBool)) - pData->SetIncludeWidthHeight( bBool ); + pData->SetWidthHeight( bBool ); // else error //! notify to other objects - pFormats->SetSaveLater(true); + pFormats->Save(); } uno::Any SAL_CALL ScAutoFormatObj::getPropertyValue( const OUString& aPropertyName ) @@ -503,24 +476,24 @@ uno::Any SAL_CALL ScAutoFormatObj::getPropertyValue( const OUString& aPropertyNa ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat(); if (IsInserted() && nFormatIndex < pFormats->size()) { - ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex); + ScAutoFormatData* pData = pFormats->GetData(nFormatIndex); assert(pData && "AutoFormat data not available"); bool bValue; bool bError = false; if (aPropertyName == SC_UNONAME_INCBACK) - bValue = pData->GetIncludeBackground(); + bValue = pData->IsBackground(); else if (aPropertyName == SC_UNONAME_INCBORD) - bValue = pData->GetIncludeFrame(); + bValue = pData->IsFrame(); else if (aPropertyName == SC_UNONAME_INCFONT) - bValue = pData->GetIncludeFont(); + bValue = pData->IsFont(); else if (aPropertyName == SC_UNONAME_INCJUST) - bValue = pData->GetIncludeJustify(); + bValue = pData->IsJustify(); else if (aPropertyName == SC_UNONAME_INCNUM) - bValue = pData->GetIncludeValueFormat(); + bValue = pData->IsValueFormat(); else if (aPropertyName == SC_UNONAME_INCWIDTH) - bValue = pData->GetIncludeWidthHeight(); + bValue = pData->IsWidthHeight(); else bError = true; // unknown property @@ -564,7 +537,7 @@ void SAL_CALL ScAutoFormatFieldObj::setPropertyValue( if ( !(pEntry && pEntry->nWID && nFormatIndex < pFormats->size()) ) return; - ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex); + ScAutoFormatData* pData = pFormats->GetData(nFormatIndex); if ( IsScItemWid( pEntry->nWID ) ) { @@ -613,7 +586,7 @@ void SAL_CALL ScAutoFormatFieldObj::setPropertyValue( if (bDone) //! Notify to other objects? - pFormats->SetSaveLater(true); + pFormats->Save(); } } else @@ -631,7 +604,7 @@ void SAL_CALL ScAutoFormatFieldObj::setPropertyValue( pData->PutItem( nFieldIndex, aOuter ); //! Notify for other objects? - pFormats->SetSaveLater(true); + pFormats->Save(); } } break; @@ -646,7 +619,7 @@ void SAL_CALL ScAutoFormatFieldObj::setPropertyValue( pData->PutItem( nFieldIndex, aOuter ); //! Notify for other objects? - pFormats->SetSaveLater(true); + pFormats->Save(); } } break; @@ -665,7 +638,7 @@ uno::Any SAL_CALL ScAutoFormatFieldObj::getPropertyValue( const OUString& aPrope if ( pEntry && pEntry->nWID && nFormatIndex < pFormats->size() ) { - const ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex); + const ScAutoFormatData* pData = pFormats->GetData(nFormatIndex); if ( IsScItemWid( pEntry->nWID ) ) { diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index fd0a668fd7a4..65db2956d28c 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include #include #include #include @@ -5183,12 +5184,18 @@ void SAL_CALL ScCellRangeObj::autoFormat( const OUString& aName ) if ( pDocSh ) { ScAutoFormat* pAutoFormat = ScGlobal::GetOrCreateAutoFormat(); - ScAutoFormat::const_iterator it = pAutoFormat->find(aName); - if (it == pAutoFormat->end()) + sal_Int16 nIndex = -1; + for (size_t i = 0; i < pAutoFormat->size(); i++) + { + if (ScAutoFormatData* pData = pAutoFormat->GetData(i)) + { + if (pData->GetName() == aName) + nIndex = i; + } + } + if (nIndex == -1) throw lang::IllegalArgumentException(); - ScAutoFormat::const_iterator itBeg = pAutoFormat->begin(); - size_t nIndex = std::distance(itBeg, it); pDocSh->GetDocFunc().AutoFormat(aRange, nullptr, nIndex, true); } diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx index 825a255a1507..7b0eda991cec 100644 --- a/sc/source/ui/view/cellsh3.cxx +++ b/sc/source/ui/view/cellsh3.cxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include +#include #include #include #include @@ -1027,9 +1029,15 @@ void ScCellShell::Execute( SfxRequest& rReq ) { const SfxStringItem& rNameItem = pReqArgs->Get( SID_AUTOFORMAT ); ScAutoFormat* pFormat = ScGlobal::GetOrCreateAutoFormat(); - ScAutoFormat::const_iterator it = pFormat->find(rNameItem.GetValue()); - ScAutoFormat::const_iterator itBeg = pFormat->begin(); - size_t nIndex = std::distance(itBeg, it); + size_t nIndex = 0; + for (size_t i = 0; i < pFormat->size(); i++) + { + if (ScAutoFormatData* pData = pFormat->GetData(i)) + { + if (pData->GetName() == rNameItem.GetValue()) + nIndex = i; + } + } pTabViewShell->AutoFormat( nIndex ); @@ -1038,13 +1046,12 @@ void ScCellShell::Execute( SfxRequest& rReq ) } else { - ScGlobal::ClearAutoFormat(); - std::unique_ptr pNewEntry(pTabViewShell->CreateAutoFormatData()); - ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); + SCTAB nCurrentTab = GetViewData().GetTabNumber(); + bool bRTL = GetViewData().GetDocument().IsLayoutRTL(nCurrentTab); - ScopedVclPtr pDlg(pFact->CreateScAutoFormatDlg(pDlgParent, ScGlobal::GetOrCreateAutoFormat(), pNewEntry.get(), GetViewData())); - - if ( pDlg->Execute() == RET_OK ) + SvxTableAutoFmtDlg aDlg(*ScGlobal::GetOrCreateAutoFormat(), "", pDlgParent, + false, bRTL); + if (aDlg.run() == RET_OK) { ScEditableTester aTester = ScEditableTester::CreateAndTestView(pTabViewShell); if ( !aTester.IsEditable() ) @@ -1053,9 +1060,10 @@ void ScCellShell::Execute( SfxRequest& rReq ) } else { - pTabViewShell->AutoFormat( pDlg->GetIndex() ); + pTabViewShell->AutoFormat(aDlg.GetIndex()); - rReq.AppendItem( SfxStringItem( SID_AUTOFORMAT, pDlg->GetCurrFormatName() ) ); + rReq.AppendItem( + SfxStringItem(SID_AUTOFORMAT, aDlg.GetCurrFormatName())); rReq.Done(); } } diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index 56c11aa7d03d..de6b1027e60a 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -8580,7 +8580,6 @@ sc/source/ui/inc/anyrefdg.hxx sc/source/ui/inc/areasave.hxx sc/source/ui/inc/areasdlg.hxx sc/source/ui/inc/asciiopt.hxx -sc/source/ui/inc/autofmt.hxx sc/source/ui/inc/autostyl.hxx sc/source/ui/inc/cbutton.hxx sc/source/ui/inc/cellmergeoption.hxx @@ -8685,7 +8684,6 @@ sc/source/ui/inc/rfindlst.hxx sc/source/ui/inc/scendlg.hxx sc/source/ui/inc/scui_def.hxx sc/source/ui/inc/scuiasciiopt.hxx -sc/source/ui/inc/scuiautofmt.hxx sc/source/ui/inc/scuiimoptdlg.hxx sc/source/ui/inc/scuitphfedit.hxx sc/source/ui/inc/searchresults.hxx @@ -8762,7 +8760,6 @@ sc/source/ui/miscdlgs/mtrindlg.cxx sc/source/ui/miscdlgs/optsolver.cxx sc/source/ui/miscdlgs/protectiondlg.cxx sc/source/ui/miscdlgs/redcom.cxx -sc/source/ui/miscdlgs/scuiautofmt.cxx sc/source/ui/miscdlgs/sharedocdlg.cxx sc/source/ui/miscdlgs/simpref.cxx sc/source/ui/miscdlgs/solveroptions.cxx