sc/qa/uitest/conditional_format/tdf100793.py | 4 sc/qa/uitest/conditional_format/tdf105544.py | 4 sc/qa/uitest/pasteSpecial/tdf86253.py | 2 sc/source/ui/condformat/condformatdlgentry.cxx | 121 +-------------- sc/source/ui/condformat/condformateasydlg.cxx | 38 +--- sc/source/ui/condformat/condformathelper.cxx | 199 ++++++++++++++++++------- sc/source/ui/condformat/condformatmgr.cxx | 47 ++++- sc/source/ui/inc/condformateasydlg.hxx | 6 sc/source/ui/inc/condformathelper.hxx | 7 sc/source/ui/inc/condformatmgr.hxx | 2 sc/uiconfig/scalc/ui/condformatmanager.ui | 2 sc/uiconfig/scalc/ui/conditionaleasydialog.ui | 30 +++ 12 files changed, 257 insertions(+), 205 deletions(-)
New commits: commit 8090d7a54f71ccf897d725bbae3f55eb346a240a Author: Pranam Lashkari <lpra...@collabora.com> AuthorDate: Wed Jun 26 00:43:54 2024 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Thu Aug 15 14:53:59 2024 +0200 tdf#162475 sc: display all the conditions of same ranges in conditional format manager Change-Id: I775f96f4cea19e8da34c2d64ac601e5ea3fc5c43 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169482 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170914 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sc/qa/uitest/conditional_format/tdf100793.py b/sc/qa/uitest/conditional_format/tdf100793.py index 692c3c8109b2..f0d2c3854db7 100644 --- a/sc/qa/uitest/conditional_format/tdf100793.py +++ b/sc/qa/uitest/conditional_format/tdf100793.py @@ -32,7 +32,7 @@ class tdf100793(UITestCase): # check that we have exactly one conditional formats in the beginning xList = xCondFormatMgr.getChild("CONTAINER") list_state = get_state_as_dict(xList) - self.assertEqual(list_state['Children'], '1') + self.assertEqual(list_state['Children'], '3') #3) Click Edit & try to change to intended one, F18:K33 xEditBtn = xCondFormatMgr.getChild("edit") @@ -65,7 +65,7 @@ class tdf100793(UITestCase): # and still only 1 conditional format in the document xList = xCondFormatMgr.getChild("CONTAINER") list_state = get_state_as_dict(xList) - self.assertEqual(list_state['Children'], '1') + self.assertEqual(list_state['Children'], '3') self.assertEqual(conditional_format_list.getLength(), 1) diff --git a/sc/qa/uitest/conditional_format/tdf105544.py b/sc/qa/uitest/conditional_format/tdf105544.py index b172d4067a1d..3e5fd6730277 100644 --- a/sc/qa/uitest/conditional_format/tdf105544.py +++ b/sc/qa/uitest/conditional_format/tdf105544.py @@ -27,7 +27,7 @@ class tdf105544(UITestCase): # check that we have exactly four conditional formats in the beginning xList = xCondFormatMgr.getChild("CONTAINER") list_state = get_state_as_dict(xList) - self.assertEqual(list_state['Children'], '4') + self.assertEqual(list_state['Children'], '5') #select B3:B37 range and click edit, then click yes xList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"})) #2nd position in the list @@ -41,7 +41,7 @@ class tdf105544(UITestCase): # check again that we still have 4 entry in the list xList = xCondFormatMgr.getChild("CONTAINER") list_state = get_state_as_dict(xList) - self.assertEqual(list_state['Children'], '4') + self.assertEqual(list_state['Children'], '5') # close the conditional format manager xOKBtn = xCondFormatMgr.getChild("ok") diff --git a/sc/qa/uitest/pasteSpecial/tdf86253.py b/sc/qa/uitest/pasteSpecial/tdf86253.py index 6e6e1bcd4983..c405a24ccdfe 100644 --- a/sc/qa/uitest/pasteSpecial/tdf86253.py +++ b/sc/qa/uitest/pasteSpecial/tdf86253.py @@ -44,7 +44,7 @@ class tdf86253(UITestCase): # check that we have exactly 1 conditional format and range is C1:C17 xList = xCondFormatMgr.getChild("CONTAINER") list_state = get_state_as_dict(xList) - self.assertEqual(list_state['Children'], '1') + self.assertEqual(list_state['Children'], '2') # We can now display both condition seprate on same range xTreeEntry = xList.getChild('0') self.assertEqual(get_state_as_dict(xTreeEntry)["Text"], "A1:A6,C1:C17 Cell value >= 0") diff --git a/sc/source/ui/condformat/condformathelper.cxx b/sc/source/ui/condformat/condformathelper.cxx index 29c397b4b629..03623db407d1 100644 --- a/sc/source/ui/condformat/condformathelper.cxx +++ b/sc/source/ui/condformat/condformathelper.cxx @@ -136,68 +136,67 @@ OUString getDateString(sal_Int32 nIndex) } -OUString ScCondFormatHelper::GetExpression(const ScConditionalFormat& rFormat, const ScAddress& rPos) +OUString ScCondFormatHelper::GetExpression(const ScFormatEntry* rEntry, const ScAddress& rPos) { OUStringBuffer aBuffer; - if(!rFormat.IsEmpty()) + switch (rEntry->GetType()) { - switch(rFormat.GetEntry(0)->GetType()) + case ScFormatEntry::Type::Condition: + case ScFormatEntry::Type::ExtCondition: { - case ScFormatEntry::Type::Condition: - case ScFormatEntry::Type::ExtCondition: + const ScConditionEntry* pEntry = static_cast<const ScConditionEntry*>(rEntry); + ScConditionMode eMode = pEntry->GetOperation(); + if (eMode == ScConditionMode::Direct) + { + aBuffer.append(getTextForType(FORMULA) + " " + pEntry->GetExpression(rPos, 0)); + } + else + { + aBuffer.append(getTextForType(CONDITION) + " " + + getExpression(static_cast<sal_Int32>(eMode)) + " "); + if (eMode == ScConditionMode::Between || eMode == ScConditionMode::NotBetween) { - const ScConditionEntry* pEntry = static_cast<const ScConditionEntry*>(rFormat.GetEntry(0)); - ScConditionMode eMode = pEntry->GetOperation(); - if(eMode == ScConditionMode::Direct) - { - aBuffer.append(getTextForType(FORMULA) - + " " - + pEntry->GetExpression(rPos, 0)); - } - else - { - aBuffer.append(getTextForType(CONDITION) - + " " - + getExpression(static_cast<sal_Int32>(eMode)) - + " "); - if(eMode == ScConditionMode::Between || eMode == ScConditionMode::NotBetween) - { - aBuffer.append(pEntry->GetExpression(rPos, 0) - + " " - + ScResId(STR_COND_AND) - + " " - + pEntry->GetExpression(rPos, 1)); - } - else if(eMode <= ScConditionMode::NotEqual || eMode >= ScConditionMode::BeginsWith) - { - aBuffer.append(pEntry->GetExpression(rPos, 0)); - } - } + aBuffer.append(pEntry->GetExpression(rPos, 0) + " " + ScResId(STR_COND_AND) + + " " + pEntry->GetExpression(rPos, 1)); } - - break; - case ScFormatEntry::Type::Databar: - aBuffer.append(getTextForType(DATABAR)); - break; - case ScFormatEntry::Type::Colorscale: - aBuffer.append(getTextForType(COLORSCALE)); - break; - case ScFormatEntry::Type::Iconset: - aBuffer.append(getTextForType(ICONSET)); - break; - case ScFormatEntry::Type::Date: + else if (eMode <= ScConditionMode::NotEqual || eMode >= ScConditionMode::BeginsWith) { - sal_Int32 nDateEntry = static_cast<sal_Int32>(static_cast<const ScCondDateFormatEntry*>(rFormat.GetEntry(0))->GetDateType()); - aBuffer.append(getTextForType(DATE) - + " " - + getDateString(nDateEntry)); + aBuffer.append(pEntry->GetExpression(rPos, 0)); } - break; + } + } + + break; + case ScFormatEntry::Type::Databar: + aBuffer.append(getTextForType(DATABAR)); + break; + case ScFormatEntry::Type::Colorscale: + aBuffer.append(getTextForType(COLORSCALE)); + break; + case ScFormatEntry::Type::Iconset: + aBuffer.append(getTextForType(ICONSET)); + break; + case ScFormatEntry::Type::Date: + { + sal_Int32 nDateEntry = static_cast<sal_Int32>( + static_cast<const ScCondDateFormatEntry*>(rEntry)->GetDateType()); + aBuffer.append(getTextForType(DATE) + " " + getDateString(nDateEntry)); } + break; } return aBuffer.makeStringAndClear(); } +OUString ScCondFormatHelper::GetExpression(const ScConditionalFormat& rFormat, + const ScAddress& rPos) +{ + if (!rFormat.IsEmpty()) + { + return ScCondFormatHelper::GetExpression(rFormat.GetEntry(0), rPos); + } + return ""; +} + OUString ScCondFormatHelper::GetExpression( ScCondFormatEntryType eType, sal_Int32 nIndex, std::u16string_view aStr1, std::u16string_view aStr2 ) { diff --git a/sc/source/ui/condformat/condformatmgr.cxx b/sc/source/ui/condformat/condformatmgr.cxx index 5dd7d2142b25..ff7f9889afaf 100644 --- a/sc/source/ui/condformat/condformatmgr.cxx +++ b/sc/source/ui/condformat/condformatmgr.cxx @@ -22,7 +22,19 @@ #include <svl/intitem.hxx> #include <svl/stritem.hxx> #include <unotools/viewoptions.hxx> -#include <iostream> +#include <o3tl/string_view.hxx> + +namespace +{ +OUString generateEntryId(sal_uInt32 key, sal_uInt32 index) +{ + return OUString::number(key) + "_" + OUString::number(index); +} + +sal_Int32 getKeyFromId(std::u16string_view id) { return o3tl::toInt32(o3tl::getToken(id, 0, '_')); } + +sal_Int32 getEntryIndexFromId(std::u16string_view id) { return o3tl::toInt32(o3tl::getToken(id, 1, '_')); } +} ScCondFormatManagerWindow::ScCondFormatManagerWindow(weld::TreeView& rTreeView, ScDocument& rDoc, ScConditionalFormatList* pFormatList) @@ -51,9 +63,14 @@ void ScCondFormatManagerWindow::Init() { const ScRangeList& aRange = rItem->GetRange(); aRange.Format(sRangeStr, ScRefFlags::VALID, mrDoc, mrDoc.GetAddressConvention()); - mrTreeView.append(OUString::number(rItem->GetKey()), sRangeStr); - mrTreeView.set_text(nRow, ScCondFormatHelper::GetExpression(*rItem, aRange.GetTopLeftCorner()), 1); - ++nRow; + for (size_t i = 0; i < rItem->size(); i++) + { + mrTreeView.append(generateEntryId(rItem->GetKey(), i), sRangeStr); + mrTreeView.set_text(nRow++, + ScCondFormatHelper::GetExpression(rItem->GetEntry(i), + aRange.GetTopLeftCorner()), + 1); + } } } @@ -81,8 +98,19 @@ ScConditionalFormat* ScCondFormatManagerWindow::GetSelection() if (nEntry == -1) return nullptr; - sal_Int32 nIndex = mrTreeView.get_id(nEntry).toInt32(); - return mpFormatList->GetFormat(nIndex); + sal_Int32 nKey = getKeyFromId(mrTreeView.get_id(nEntry)); + return mpFormatList->GetFormat(nKey); +} + +const ScFormatEntry* ScCondFormatManagerWindow::GetSelectedEntry() +{ + OUString id = mrTreeView.get_selected_id(); + if (id.isEmpty()) + return nullptr; + + sal_Int32 nKey = getKeyFromId(id); + sal_Int32 nEntryIndex = getEntryIndexFromId(id); + return mpFormatList->GetFormat(nKey)->GetEntry(nEntryIndex); } void ScCondFormatManagerWindow::setColSizes() @@ -252,12 +280,7 @@ IMPL_LINK_NOARG(ScCondFormatManagerDlg, ComboHdl, weld::ComboBox&, void) IMPL_LINK_NOARG(ScCondFormatManagerDlg, EntryFocus, weld::TreeView&, void) { - ScConditionalFormat* conditionFrmt = m_xCtrlManager->GetSelection(); - - if (!conditionFrmt) - return; - - const ScFormatEntry* entry = conditionFrmt->GetEntry(0); + const ScFormatEntry* entry = m_xCtrlManager->GetSelectedEntry(); if (!entry) return; auto type = entry->GetType(); diff --git a/sc/source/ui/inc/condformathelper.hxx b/sc/source/ui/inc/condformathelper.hxx index 35e3b5c9e9be..b1ff300b1a88 100644 --- a/sc/source/ui/inc/condformathelper.hxx +++ b/sc/source/ui/inc/condformathelper.hxx @@ -14,6 +14,7 @@ #include <svx/fntctrl.hxx> class ScConditionalFormat; +class ScFormatEntry; enum ScCondFormatEntryType { @@ -28,6 +29,7 @@ enum ScCondFormatEntryType class ScCondFormatHelper { public: + static SC_DLLPUBLIC OUString GetExpression(const ScFormatEntry* rEntry, const ScAddress& rPos); static SC_DLLPUBLIC OUString GetExpression(const ScConditionalFormat& rFormat, const ScAddress& rPos); static SC_DLLPUBLIC OUString GetExpression( ScCondFormatEntryType eType, sal_Int32 nIndex, diff --git a/sc/source/ui/inc/condformatmgr.hxx b/sc/source/ui/inc/condformatmgr.hxx index 26345d55894a..09b6c571e562 100644 --- a/sc/source/ui/inc/condformatmgr.hxx +++ b/sc/source/ui/inc/condformatmgr.hxx @@ -15,6 +15,7 @@ class ScDocument; class ScConditionalFormat; class ScConditionalFormatList; +class ScFormatEntry; class ScCondFormatManagerWindow { @@ -31,6 +32,7 @@ public: void DeleteSelection(); ScConditionalFormat* GetSelection(); + const ScFormatEntry* GetSelectedEntry(); }; class ScCondFormatManagerDlg : public weld::GenericDialogController diff --git a/sc/uiconfig/scalc/ui/condformatmanager.ui b/sc/uiconfig/scalc/ui/condformatmanager.ui index f6bad84e5e7c..0e143b622beb 100644 --- a/sc/uiconfig/scalc/ui/condformatmanager.ui +++ b/sc/uiconfig/scalc/ui/condformatmanager.ui @@ -139,7 +139,7 @@ <object class="GtkTreeViewColumn" id="treeviewcolumn2"> <property name="resizable">True</property> <property name="spacing">6</property> - <property name="title" translatable="yes" context="condformatmanager|STR_HEADER_FIRST_CONDITION">First Condition</property> + <property name="title" translatable="yes" context="condformatmanager|STR_HEADER_FIRST_CONDITION">Condition</property> <child> <object class="GtkCellRendererText" id="cellrenderer2"/> <attributes> commit 367c2319a8067e6929a4df5c199698db9b07cc56 Author: Pranam Lashkari <lpra...@collabora.com> AuthorDate: Wed Jun 26 00:50:58 2024 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Thu Aug 15 14:53:48 2024 +0200 tdf#162475 sc: preview style in easy format dialog Change-Id: If9c96129daefd5100b4211c9b3b07953b603166d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169483 Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170913 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sc/source/ui/condformat/condformatdlgentry.cxx b/sc/source/ui/condformat/condformatdlgentry.cxx index 72b4025a46c7..605b960c15de 100644 --- a/sc/source/ui/condformat/condformatdlgentry.cxx +++ b/sc/source/ui/condformat/condformatdlgentry.cxx @@ -108,26 +108,6 @@ void ScCondFrmtEntry::Deselect() mbActive = false; } -//condition - -namespace { - -void FillStyleListBox( const ScDocument* pDoc, weld::ComboBox& rLbStyle ) -{ - std::set<OUString> aStyleNames; - SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SfxStyleFamily::Para ); - for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() ) - { - aStyleNames.insert(pStyle->GetName()); - } - for(const auto& rStyleName : aStyleNames) - { - rLbStyle.append_text(rStyleName); - } -} - -} - const ScConditionMode ScConditionFrmtEntry::mpEntryToCond[ScConditionFrmtEntry::NUM_COND_ENTRIES] = { ScConditionMode::Equal, ScConditionMode::Less, @@ -241,7 +221,7 @@ void ScConditionFrmtEntry::Init(ScCondFormatDlg* pDialogParent) mxEdVal1->SetModifyHdl( LINK( this, ScConditionFrmtEntry, OnEdChanged ) ); mxEdVal2->SetModifyHdl( LINK( this, ScConditionFrmtEntry, OnEdChanged ) ); - FillStyleListBox( mpDoc, *mxLbStyle ); + ScCondFormatHelper::FillStyleListBox(mpDoc, *mxLbStyle); mxLbStyle->connect_changed( LINK( this, ScConditionFrmtEntry, StyleSelectHdl ) ); mxLbCondType->connect_changed( LINK( this, ScConditionFrmtEntry, ConditionTypeSelectHdl ) ); @@ -437,104 +417,19 @@ void ScConditionFrmtEntry::SetInactive() Deselect(); } -namespace { - -void UpdateStyleList(weld::ComboBox& rLbStyle, const ScDocument* pDoc) -{ - OUString aSelectedStyle = rLbStyle.get_active_text(); - for (sal_Int32 i = rLbStyle.get_count(); i > 1; --i) - rLbStyle.remove(i - 1); - FillStyleListBox(pDoc, rLbStyle); - rLbStyle.set_active_text(aSelectedStyle); -} - -} - void ScConditionFrmtEntry::Notify(SfxBroadcaster&, const SfxHint& rHint) { if(rHint.GetId() == SfxHintId::StyleSheetModified || rHint.GetId() == SfxHintId::StyleSheetModifiedExtended) { if(!mbIsInStyleCreate) - UpdateStyleList(*mxLbStyle, mpDoc); + ScCondFormatHelper::UpdateStyleList(*mxLbStyle, mpDoc); } } -namespace { - -void StyleSelect(weld::Window* pDialogParent, weld::ComboBox& rLbStyle, const ScDocument* pDoc, SvxFontPrevWindow& rWdPreview) -{ - if (rLbStyle.get_active() == 0) - { - // call new style dialog - SfxUInt16Item aFamilyItem( SID_STYLE_FAMILY, sal_uInt16(SfxStyleFamily::Para) ); - SfxStringItem aRefItem( SID_STYLE_REFERENCE, ScResId(STR_STYLENAME_STANDARD) ); - css::uno::Any aAny(pDialogParent->GetXWindow()); - SfxUnoAnyItem aDialogParent( SID_DIALOG_PARENT, aAny ); - - // unlock the dispatcher so SID_STYLE_NEW can be executed - // (SetDispatcherLock would affect all Calc documents) - if (ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell()) - { - if (SfxDispatcher* pDisp = pViewShell->GetDispatcher()) - { - bool bLocked = pDisp->IsLocked(); - if (bLocked) - pDisp->Lock(false); - - // Execute the "new style" slot, complete with undo and all necessary updates. - // The return value (SfxUInt16Item) is ignored, look for new styles instead. - pDisp->ExecuteList(SID_STYLE_NEW, - SfxCallMode::SYNCHRON | SfxCallMode::RECORD, - { &aFamilyItem, &aRefItem }, { &aDialogParent }); - - if (bLocked) - pDisp->Lock(true); - - // Find the new style and add it into the style list boxes - SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SfxStyleFamily::Para ); - bool bFound = false; - for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle && !bFound; pStyle = aStyleIter.Next() ) - { - const OUString& aName = pStyle->GetName(); - if (rLbStyle.find_text(aName) == -1) // all lists contain the same entries - { - for( sal_Int32 i = 1, n = rLbStyle.get_count(); i <= n && !bFound; ++i) - { - OUString aStyleName = ScGlobal::getCharClass().uppercase(rLbStyle.get_text(i)); - if( i == n ) - { - rLbStyle.append_text(aName); - rLbStyle.set_active_text(aName); - bFound = true; - } - else if( aStyleName > ScGlobal::getCharClass().uppercase(aName) ) - { - rLbStyle.insert_text(i, aName); - rLbStyle.set_active_text(aName); - bFound = true; - } - } - } - } - } - } - } - - OUString aStyleName = rLbStyle.get_active_text(); - SfxStyleSheetBase* pStyleSheet = pDoc->GetStyleSheetPool()->Find( aStyleName, SfxStyleFamily::Para ); - if(pStyleSheet) - { - const SfxItemSet& rSet = pStyleSheet->GetItemSet(); - rWdPreview.SetFromItemSet(rSet, false); - } -} - -} - IMPL_LINK_NOARG(ScConditionFrmtEntry, StyleSelectHdl, weld::ComboBox&, void) { mbIsInStyleCreate = true; - StyleSelect(mpParent->GetFrameWeld(), *mxLbStyle, mpDoc, maWdPreview); + ScCondFormatHelper::StyleSelect(mpParent->GetFrameWeld(), *mxLbStyle, mpDoc, maWdPreview); mbIsInStyleCreate = false; } @@ -576,13 +471,13 @@ void ScFormulaFrmtEntry::Init(ScCondFormatDlg* pDialogParent) { mxEdFormula->SetGetFocusHdl( LINK( pDialogParent, ScCondFormatDlg, RangeGetFocusHdl ) ); - FillStyleListBox( mpDoc, *mxLbStyle ); + ScCondFormatHelper::FillStyleListBox(mpDoc, *mxLbStyle); mxLbStyle->connect_changed( LINK( this, ScFormulaFrmtEntry, StyleSelectHdl ) ); } IMPL_LINK_NOARG(ScFormulaFrmtEntry, StyleSelectHdl, weld::ComboBox&, void) { - StyleSelect(mpParent->GetFrameWeld(), *mxLbStyle, mpDoc, maWdPreview); + ScCondFormatHelper::StyleSelect(mpParent->GetFrameWeld(), *mxLbStyle, mpDoc, maWdPreview); } ScFormatEntry* ScFormulaFrmtEntry::createFormulaEntry() const @@ -1292,7 +1187,7 @@ void ScDateFrmtEntry::Init() mxLbDateEntry->set_active(0); mxLbType->set_active(3); - FillStyleListBox( mpDoc, *mxLbStyle ); + ScCondFormatHelper::FillStyleListBox(mpDoc, *mxLbStyle); mxLbStyle->connect_changed( LINK( this, ScDateFrmtEntry, StyleSelectHdl ) ); mxLbStyle->set_active(1); } @@ -1322,7 +1217,7 @@ void ScDateFrmtEntry::Notify( SfxBroadcaster&, const SfxHint& rHint ) if(rHint.GetId() == SfxHintId::StyleSheetModified || rHint.GetId() == SfxHintId::StyleSheetModifiedExtended) { if(!mbIsInStyleCreate) - UpdateStyleList(*mxLbStyle, mpDoc); + ScCondFormatHelper::UpdateStyleList(*mxLbStyle, mpDoc); } } @@ -1344,7 +1239,7 @@ OUString ScDateFrmtEntry::GetExpressionString() IMPL_LINK_NOARG( ScDateFrmtEntry, StyleSelectHdl, weld::ComboBox&, void ) { mbIsInStyleCreate = true; - StyleSelect(mpParent->GetFrameWeld(), *mxLbStyle, mpDoc, maWdPreview); + ScCondFormatHelper::StyleSelect(mpParent->GetFrameWeld(), *mxLbStyle, mpDoc, maWdPreview); mbIsInStyleCreate = false; } diff --git a/sc/source/ui/condformat/condformateasydlg.cxx b/sc/source/ui/condformat/condformateasydlg.cxx index fcf011efe06a..9379bc323b18 100644 --- a/sc/source/ui/condformat/condformateasydlg.cxx +++ b/sc/source/ui/condformat/condformateasydlg.cxx @@ -6,32 +6,10 @@ #include <scresid.hxx> #include <svl/style.hxx> #include <strings.hrc> +#include <condformathelper.hxx> namespace { -void FillStyleListBox(const ScDocument* pDocument, weld::ComboBox& rCombo) -{ - std::set<OUString> aStyleNames; - SfxStyleSheetIterator aStyleIter(pDocument->GetStyleSheetPool(), SfxStyleFamily::Para); - for (SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next()) - { - aStyleNames.insert(pStyle->GetName()); - } - for (const auto& rStyleName : aStyleNames) - { - rCombo.append_text(rStyleName); - } -} - -void UpdateStyleList(const ScDocument* pDocument, weld::ComboBox& rCombo) -{ - OUString sSelectedStyle = rCombo.get_active_text(); - for (sal_Int32 i = rCombo.get_count(); i > 1; --i) - rCombo.remove(i - 1); - FillStyleListBox(pDocument, rCombo); - rCombo.set_active_text(sSelectedStyle); -} - condformat::ScCondFormatDateType GetScCondFormatDateType(ScConditionMode mode) { switch (mode) @@ -82,6 +60,7 @@ ConditionalFormatEasyDialog::ConditionalFormatEasyDialog(SfxBindings* pBindings, : ScAnyRefDlgController(pBindings, pChildWindow, pParent, u"modules/scalc/ui/conditionaleasydialog.ui"_ustr, u"CondFormatEasyDlg"_ustr) + , mpParent(pParent) , mpViewData(pViewData) , mpDocument(&mpViewData->GetDocument()) , mbIsManaged(false) @@ -91,6 +70,8 @@ ConditionalFormatEasyDialog::ConditionalFormatEasyDialog(SfxBindings* pBindings, , mxRangeEntry(new formula::RefEdit(m_xBuilder->weld_entry(u"entryRange"_ustr))) , mxButtonRangeEdit(new formula::RefButton(m_xBuilder->weld_button(u"rbassign"_ustr))) , mxStyles(m_xBuilder->weld_combo_box(u"themeCombo"_ustr)) + , mxWdPreviewWin(m_xBuilder->weld_widget("previewwin")) + , mxWdPreview(new weld::CustomWeld(*m_xBuilder, "preview", maWdPreview)) , mxDescription(m_xBuilder->weld_label(u"description"_ustr)) , mxButtonOk(m_xBuilder->weld_button(u"ok"_ustr)) , mxButtonCancel(m_xBuilder->weld_button(u"cancel"_ustr)) @@ -262,6 +243,7 @@ ConditionalFormatEasyDialog::ConditionalFormatEasyDialog(SfxBindings* pBindings, mxButtonOk->connect_clicked(LINK(this, ConditionalFormatEasyDialog, ButtonPressed)); mxButtonCancel->connect_clicked(LINK(this, ConditionalFormatEasyDialog, ButtonPressed)); + mxStyles->connect_changed(LINK(this, ConditionalFormatEasyDialog, StyleSelectHdl)); ScRangeList aRange; mpViewData->GetMarkData().FillRangeListWithMarks(&aRange, false); @@ -277,9 +259,10 @@ ConditionalFormatEasyDialog::ConditionalFormatEasyDialog(SfxBindings* pBindings, mxRangeEntry->SetText(sRangeString); StartListening(*mpDocument->GetStyleSheetPool(), DuplicateHandling::Prevent); - FillStyleListBox(mpDocument, *mxStyles); + ScCondFormatHelper::FillStyleListBox(mpDocument, *mxStyles); mxStyles->set_active(1); + mxWdPreviewWin->show(); } ConditionalFormatEasyDialog::~ConditionalFormatEasyDialog() @@ -295,7 +278,7 @@ void ConditionalFormatEasyDialog::Notify(SfxBroadcaster&, const SfxHint& rHint) { if (rHint.GetId() == SfxHintId::StyleSheetModified || rHint.GetId() == SfxHintId::StyleSheetModifiedExtended) - UpdateStyleList(mpDocument, *mxStyles); + ScCondFormatHelper::UpdateStyleList(*mxStyles, mpDocument); } void ConditionalFormatEasyDialog::SetReference(const ScRange& rRange, ScDocument&) @@ -393,4 +376,9 @@ IMPL_LINK(ConditionalFormatEasyDialog, ButtonPressed, weld::Button&, rButton, vo m_xDialog->response(RET_CANCEL); } +IMPL_LINK_NOARG(ConditionalFormatEasyDialog, StyleSelectHdl, weld::ComboBox&, void) +{ + ScCondFormatHelper::StyleSelect(mpParent, *mxStyles, &(mpViewData->GetDocument()), maWdPreview); +} + } // namespace sc diff --git a/sc/source/ui/condformat/condformathelper.cxx b/sc/source/ui/condformat/condformathelper.cxx index 86feddad8e6d..29c397b4b629 100644 --- a/sc/source/ui/condformat/condformathelper.cxx +++ b/sc/source/ui/condformat/condformathelper.cxx @@ -15,6 +15,14 @@ #include <globstr.hrc> #include <scresid.hxx> #include <conditio.hxx> +#include <stlpool.hxx> +#include <svl/lstner.hxx> +#include <svl/stritem.hxx> +#include <svl/intitem.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/frame.hxx> +#include <tabvwsh.hxx> +#include <svx/fntctrl.hxx> namespace { @@ -222,4 +230,98 @@ OUString ScCondFormatHelper::GetExpression( ScCondFormatEntryType eType, sal_Int return aBuffer.makeStringAndClear(); } +void ScCondFormatHelper::StyleSelect(weld::Window* pDialogParent, weld::ComboBox& rLbStyle, + const ScDocument* pDoc, SvxFontPrevWindow& rWdPreview) +{ + if (rLbStyle.get_active() == 0) + { + // call new style dialog + SfxUInt16Item aFamilyItem(SID_STYLE_FAMILY, sal_uInt16(SfxStyleFamily::Para)); + SfxStringItem aRefItem(SID_STYLE_REFERENCE, ScResId(STR_STYLENAME_STANDARD)); + css::uno::Any aAny(pDialogParent->GetXWindow()); + SfxUnoAnyItem aDialogParent(SID_DIALOG_PARENT, aAny); + + // unlock the dispatcher so SID_STYLE_NEW can be executed + // (SetDispatcherLock would affect all Calc documents) + if (ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell()) + { + if (SfxDispatcher* pDisp = pViewShell->GetDispatcher()) + { + bool bLocked = pDisp->IsLocked(); + if (bLocked) + pDisp->Lock(false); + + // Execute the "new style" slot, complete with undo and all necessary updates. + // The return value (SfxUInt16Item) is ignored, look for new styles instead. + pDisp->ExecuteList(SID_STYLE_NEW, SfxCallMode::SYNCHRON | SfxCallMode::RECORD, + { &aFamilyItem, &aRefItem }, { &aDialogParent }); + + if (bLocked) + pDisp->Lock(true); + + // Find the new style and add it into the style list boxes + SfxStyleSheetIterator aStyleIter(pDoc->GetStyleSheetPool(), SfxStyleFamily::Para); + bool bFound = false; + for (SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle && !bFound; + pStyle = aStyleIter.Next()) + { + const OUString& aName = pStyle->GetName(); + if (rLbStyle.find_text(aName) == -1) // all lists contain the same entries + { + for (sal_Int32 i = 1, n = rLbStyle.get_count(); i <= n && !bFound; ++i) + { + OUString aStyleName + = ScGlobal::getCharClass().uppercase(rLbStyle.get_text(i)); + if (i == n) + { + rLbStyle.append_text(aName); + rLbStyle.set_active_text(aName); + bFound = true; + } + else if (aStyleName > ScGlobal::getCharClass().uppercase(aName)) + { + rLbStyle.insert_text(i, aName); + rLbStyle.set_active_text(aName); + bFound = true; + } + } + } + } + } + } + } + + OUString aStyleName = rLbStyle.get_active_text(); + SfxStyleSheetBase* pStyleSheet + = pDoc->GetStyleSheetPool()->Find(aStyleName, SfxStyleFamily::Para); + if (pStyleSheet) + { + const SfxItemSet& rSet = pStyleSheet->GetItemSet(); + rWdPreview.SetFromItemSet(rSet, false); + } +} + +void ScCondFormatHelper::FillStyleListBox(const ScDocument* pDocument, weld::ComboBox& rCombo) +{ + std::set<OUString> aStyleNames; + SfxStyleSheetIterator aStyleIter(pDocument->GetStyleSheetPool(), SfxStyleFamily::Para); + for (SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next()) + { + aStyleNames.insert(pStyle->GetName()); + } + for (const auto& rStyleName : aStyleNames) + { + rCombo.append_text(rStyleName); + } +} + +void ScCondFormatHelper::UpdateStyleList(weld::ComboBox& rLbStyle, const ScDocument* pDoc) +{ + OUString aSelectedStyle = rLbStyle.get_active_text(); + for (sal_Int32 i = rLbStyle.get_count(); i > 1; --i) + rLbStyle.remove(i - 1); + ScCondFormatHelper::FillStyleListBox(pDoc, rLbStyle); + rLbStyle.set_active_text(aSelectedStyle); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/condformateasydlg.hxx b/sc/source/ui/inc/condformateasydlg.hxx index e9d2f24a80a9..baa6208dc061 100644 --- a/sc/source/ui/inc/condformateasydlg.hxx +++ b/sc/source/ui/inc/condformateasydlg.hxx @@ -12,6 +12,7 @@ #include "anyrefdg.hxx" #include <svl/lstner.hxx> #include <conditio.hxx> +#include <svx/fntctrl.hxx> class ScViewData; class ScConditionalFormat; @@ -32,10 +33,12 @@ public: virtual void Notify(SfxBroadcaster&, const SfxHint&) override; DECL_LINK(ButtonPressed, weld::Button&, void); + DECL_LINK(StyleSelectHdl, weld::ComboBox&, void); private: void SetDescription(std::u16string_view rCondition); + weld::Window* mpParent; ScViewData* mpViewData; ScDocument* mpDocument; ScConditionMode meMode; @@ -43,12 +46,15 @@ private: OUString msFormula; ScAddress maPosition; + SvxFontPrevWindow maWdPreview; std::unique_ptr<weld::Entry> mxNumberEntry; std::unique_ptr<weld::Entry> mxNumberEntry2; std::unique_ptr<weld::Container> mxAllInputs; std::unique_ptr<formula::RefEdit> mxRangeEntry; std::unique_ptr<formula::RefButton> mxButtonRangeEdit; std::unique_ptr<weld::ComboBox> mxStyles; + std::unique_ptr<weld::Widget> mxWdPreviewWin; + std::unique_ptr<weld::CustomWeld> mxWdPreview; std::unique_ptr<weld::Label> mxDescription; std::unique_ptr<weld::Button> mxButtonOk; std::unique_ptr<weld::Button> mxButtonCancel; diff --git a/sc/source/ui/inc/condformathelper.hxx b/sc/source/ui/inc/condformathelper.hxx index 9e4a0768dbb4..35e3b5c9e9be 100644 --- a/sc/source/ui/inc/condformathelper.hxx +++ b/sc/source/ui/inc/condformathelper.hxx @@ -11,6 +11,7 @@ #include <rtl/ustring.hxx> #include <address.hxx> +#include <svx/fntctrl.hxx> class ScConditionalFormat; @@ -31,6 +32,10 @@ public: static SC_DLLPUBLIC OUString GetExpression( ScCondFormatEntryType eType, sal_Int32 nIndex, std::u16string_view aStr1 = std::u16string_view(), std::u16string_view aStr2 = std::u16string_view() ); + static SC_DLLPUBLIC void StyleSelect(weld::Window* pDialogParent, weld::ComboBox& rLbStyle, + const ScDocument* pDoc, SvxFontPrevWindow& rWdPreview); + static SC_DLLPUBLIC void FillStyleListBox(const ScDocument* pDocument, weld::ComboBox& rCombo); + static SC_DLLPUBLIC void UpdateStyleList(weld::ComboBox& rLbStyle, const ScDocument* pDoc); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/uiconfig/scalc/ui/conditionaleasydialog.ui b/sc/uiconfig/scalc/ui/conditionaleasydialog.ui index 3939d49f613b..0f3348bc5c8e 100644 --- a/sc/uiconfig/scalc/ui/conditionaleasydialog.ui +++ b/sc/uiconfig/scalc/ui/conditionaleasydialog.ui @@ -176,6 +176,9 @@ <object class="GtkComboBoxText" id="themeCombo"> <property name="visible">True</property> <property name="can-focus">False</property> + <items> + <item translatable="yes" context="conditionaleasydialog|style">New Style...</item> + </items> <accessibility> <relation type="labelled-by" target="with"/> </accessibility> @@ -290,6 +293,33 @@ <property name="position">1</property> </packing> </child> + <child> + <object class="GtkScrolledWindow" id="previewwin"> + <property name="can-focus">True</property> + <property name="no-show-all">True</property> + <property name="hscrollbar-policy">never</property> + <property name="vscrollbar-policy">never</property> + <property name="shadow-type">in</property> + <child> + <object class="GtkViewport"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <child> + <object class="GtkDrawingArea" id="preview"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="tooltip-text" translatable="yes" context="conditionaleasydialog|preview|tooltip_text">Example</property> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> </object> <packing> <property name="expand">False</property>